• Codeforces Round #659 (Div. 2)


    A. Common Prefixes

    题目链接

    代码:

    #include<bits/stdc++.h>
    using namespace std;
    const int maxn =  1e6 + 10;
    #define ll long long
    #define ios std::ios::sync_with_stdio(false)
    const ll INF(0x3f3f3f3f3f3f3f3fll);
    const int inf(0x3f3f3f3f);
    const int mod = 998244353;
    int a[maxn];
    signed main()
    {
        ios,cin.tie(0);
        int t;
        cin >> t;
        while(t --){
            int n;
            cin >> n;
            int sum = 0;
            for(int i = 1 ; i <= n ; i ++) cin >> a[i] , sum = (sum ^ a[i]);
            if(sum == 0){
                cout << "DRAW
    ";
            }
            else{
                int pos = 0;
                for(int i = 32 ; i >= 0 ; i --){
                    if((sum >> i) & 1){
                        pos = i;
                        break;
                    }
                }
                int cnt = 0;
                for(int i = 1 ; i <= n ; i ++){
                    if((a[i] >> pos) & 1){
                        cnt ++;
                    }
                }///
                if(cnt % 4 == 1 || n % 2 == 0){
                    cout << "WIN
    ";
                }
                else cout << "LOSE
    ";
    
            }
        }
        return 0;
    }
    View Code

    C. String Transformation 1

    题目链接

    题意:

      给字符串 A 和 B , 可以通过多少次以下操作 , 使得 A = B ,最小化操作数。

      操作是 :

        ①.选定A字符串中一些相同的字符x (比如x = 'a')

        ②.选一个 比x更大的字符y(比如x = 'a' , 然后我选 y= 'c')

        ③.把 选定A中的位置 全部换成  y(比如x = 'a' , 然后 y =  'c' , 然后把你选的所有位置的 ‘a' 都换成 'c')

    想法:

      

    代码:

    #include<bits/stdc++.h>
    using namespace std;
    const int maxn =  1e5 + 10;
    #define ll long long
    #define ios std::ios::sync_with_stdio(false)
    const ll INF(0x3f3f3f3f3f3f3f3fll);
    const int inf(0x3f3f3f3f);
    #define int long long
    #define pb(a) push_back(a)
    #define debug(a) cout << "a : " << a << '
    '
    #define mp(a , b) make_pair(a ,b)
    string a , b;
    int change[100][100];
    signed main()
    {
        ios;
        cin.tie(0);
        int t;
        cin >> t;
        while(t --){
            memset(change , 0 , sizeof(change));
            int n;
            cin >> n;
            cin >> a >> b;
            bool ok = true;
            for(int i  = 0 ; i < n ; i ++){
                if(a[i] > b[i]){
                    ok = false;
                    break;
                }
            }
            if(!ok){
                cout << "-1
    ";
                continue;
            }
            int ans = 0;
            for(int i = 0 ; i < n ; i ++){
                if(a[i] != b[i]){
                    change[a[i] - 'a'][b[i] - 'a'] ++;
                }
            }
            for(int i = 0  ; i <= 20 ; i ++){
                int pos = -1;
                for(int j = i + 1 ; j <= 20 ; j ++){
                    if(change[i][j]){
                        pos = j;
                        break;
                    }
                }
                if(pos == -1)continue;
                for(int j = pos + 1 ; j <= 20 ; j ++){
                    if(change[i][j])change[pos][j] += change[i][j];
                }
                ans ++;
            }
            cout << ans << '
    ';
    
        }
        return 0;
    }
    View Code

    D. GameGame

    题目链接

    题意:

      给定一个数组a[] , 两个人初始数为0 , 轮流拿走数组中的一个数直到数组为空 , 把手里的数全部异或起来 ,谁的数更大就谁赢。(两个人都会选择当前对自己最优的拿法)

    想法:

      

    代码:

    #include<bits/stdc++.h>
    using namespace std;
    const int maxn =  1e6 + 10;
    #define ll long long
    #define ios std::ios::sync_with_stdio(false)
    int a[maxn];
    signed main()
    {
        ios,cin.tie(0);
        int t;
        cin >> t;
        while(t --){
            int n;
            cin >> n;
            int sum = 0;
            for(int i = 1 ; i <= n ; i ++) cin >> a[i] , sum = (sum ^ a[i]);
            if(sum == 0){
                cout << "DRAW
    ";
            }
            else{
                int pos = 0;
                for(int i = 32 ; i >= 0 ; i --){
                    if((sum >> i) & 1){
                        pos = i;
                        break;
                    }
                }
                int cnt = 0;
                for(int i = 1 ; i <= n ; i ++){
                    if((a[i] >> pos) & 1){
                        cnt ++;
                    }
                }///
                if(cnt % 4 == 1 || n % 2 == 0){
                    cout << "WIN
    ";
                }
                else cout << "LOSE
    ";
    
            }
        }
        return 0;
    }
    View Code
  • 相关阅读:
    poj 1466 Girls and Boys
    poj 1486 Sorting Slides
    poj 2112 Optimal Milking
    poj 1274 The Perfect Stall
    SHoj 420 购买装备
    poj 2987 Firing
    SHoj A序列
    FOJ Problem 2271 X
    XidianOJ 1028 数字工程
    XidianOJ 1030 三数和
  • 原文地址:https://www.cnblogs.com/GoodVv/p/13394637.html
Copyright © 2020-2023  润新知