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
  • 相关阅读:
    前端笔试题目总结——应用JavaScript函数递归打印数组到HTML页面上
    HTM5新增结构化元素&非结构化元素&新增属性详解
    HTML 5 与HTML 4 的区别
    HTML5框架、背景和实体、XHTML的使用规范
    百度前端笔试题目--css 实现一个带尖角的正方形
    HTML5表单提交和PHP环境搭建
    HTML5列表、块、布局
    HTML5 格式化、样式、链接、表格
    2020-09-13助教一周总结(第二周)
    2020-09-10上课小结
  • 原文地址:https://www.cnblogs.com/GoodVv/p/13394637.html
Copyright © 2011-2022 走看看