0
点赞
收藏
分享

微信扫一扫

Codeforces Round #770 (Div. 2) B. Fortune Telling

写心之所想 2022-02-12 阅读 61
算法

题目描述

Alice和Bob算命,过程如下:
给定数组a包含n个数,Alice的起始数为x,Bob的起始数为x+3,两个人对数组a中的每一个数进行下边的其中一个操作,给定一个数y,问谁最后得到的数和y相同,两个操作如下:

  • 将当前数d变为d+ai
  • 将当前数d变为d异或ai

两个操作是加法和异或,异或是进行位运算,运算法则为同0异1,即
0 xor 0 = 0
0 xor 1 = 1
1 xor 0 = 1
1 xor 1 = 0
异或的运算和加法的运算是一致的,题目说一定有一个人可以得到y,那么对于数组每个数,都进行异或或者加法即可,判断谁最后得到的数的最后一位和y相同即可。

#include <iostream>
#include <cstring>
#include <algorithm>

using namespace std;

const int N = 100010;

int a[N];

void solve()
{ 
    int n;
    long long x, y, cur;
    cin >> n >> x >> y;
    cur = x;
    for(int i = 0; i < n; i ++) 
    {
        int t; cin >> t;
        cur += t;
    }
    if(cur % 2 == y % 2) puts("Alice");
    else puts("Bob");
}

int main()
{
    int t; cin >> t;
    while(t --) solve();
    return 0;
}
举报

相关推荐

0 条评论