码迷,mamicode.com
首页 > 其他好文 > 详细

Codeforces Round #659 (Div. 2)

时间:2020-07-29 09:52:41      阅读:58      评论:0      收藏:0      [点我收藏+]

标签:common   题意   ios   format   ack   ORC   style   一个   col   

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\n";
        }
        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\n";
            }
            else cout << "LOSE\n";

        }
    }
    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 << ‘\n‘
#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\n";
            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 << \n;

    }
    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\n";
        }
        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\n";
            }
            else cout << "LOSE\n";

        }
    }
    return 0;
}
View Code

Codeforces Round #659 (Div. 2)

标签:common   题意   ios   format   ack   ORC   style   一个   col   

原文地址:https://www.cnblogs.com/GoodVv/p/13394637.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!