zoukankan      html  css  js  c++  java
  • 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
  • 相关阅读:
    织梦开发——相关阅读likeart应用
    织梦标签教程
    织梦专题调用代码
    HIT 2543 Stone IV
    POJ 3680 Intervals
    HIT 2739 The Chinese Postman Problem
    POJ 1273 Drainage Ditches
    POJ 2455 Secret Milking Machine
    SPOJ 371 Boxes
    HIT 2715 Matrix3
  • 原文地址:https://www.cnblogs.com/GoodVv/p/13394637.html
Copyright © 2011-2022 走看看