zoukankan      html  css  js  c++  java
  • codeforces 777 B

    有2个人 a b

    给你2串数子的长度

    每个人每一轮出一个数  a顺序 b可以任意

    然后求 b至少输掉几盘 a最多输掉几盘 

    显然要先统计一下数字

    然后针对着来

    1 求B能赢的和平局的  0 - 9模拟  取a中相对小的    然后计数  

    2 b尽量赢 去掉a相对大的  输出即可

    #include <iostream>
    #include<string.h>
    #include<stdio.h>
    #include<algorithm>
    
    using namespace std ;
    
    #define LL long long
    #define MAXN 1010
    char s1[MAXN],s2[MAXN];
    int a[15],b[15];
    int c[15],d[15];
    
    int main()
    {
        int n;
        scanf("%d",&n);
        scanf("%s%s",s1,s2);
        int i;
        for(i=0;i<n;i++)
        {
            a[s1[i]-'0']++;
            b[s2[i]-'0']++;
        }
        for(i=0;i<10;i++)
        {
            c[i]=a[i];
            d[i]=b[i];
        }
        int j=0;
        i=0;
        int ans1=n;
        while(1)
        {
            while(a[i]<=0&&i<=9)
                i++;
            while(j<=9&&(j<i||b[j]<=0))
                j++;
            if(i==10||j==10)
                break;
            while(a[i]>0&&b[j]>0)
            {
                a[i]--;
                b[j]--;
                ans1--;
            }
        }
        int ans2=0;
        i=9,j=9;
        while(1)
        {
            while(d[j]<=0&&j>=0)
                j--;
            while((c[i]<=0||i>=j)&&i>=0)
                i--;
            if(j==-1||i==-1)
                break;
            while(c[i]>0&&d[j]>0)
            {
                c[i]--;
                d[j]--;
                ans2++;
            }
        }
        printf("%d
    %d
    ",ans1,ans2);
        return 0 ;
    }
  • 相关阅读:
    import()函数
    node-sass安装报错
    npm 安装扩展模块时,因缓存报错的问题汇总
    测试
    export default 和 export 区别
    正则
    物联网
    第十二次课堂总结
    第十二次作业
    作业10
  • 原文地址:https://www.cnblogs.com/cherryMJY/p/6480736.html
Copyright © 2011-2022 走看看