Codeforces Round 770 (Div. 2)题解

B. Fortune Telling

题意:给定一个数列a,初值x和x1(=x+3)和终值y。问能否从$a_1$开始经过若干个+或xor,得到终值y。例如a={1,2,3,4},x=0,x1=3,y=1。3+1+2 xor 3 xor 4 = 1。

题解:不论是进行加法操作还是异或操作,数列中的偶数不会影响当前的奇偶性,奇数会改变当前的奇偶性。因此让x从$a_1$开始进行异或就能得到经过一系列加法或异或操作产生的答案是奇数还是偶数。如果与终值的奇偶性相同,那么Alice获胜,否则Bob获胜。

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<string>
#include<iostream>
#include<sstream>
#include<vector>
#include<list>
#include<stack>
#include<queue>
#include<set>
#include<map>
#include<bitset>
#include<limits.h>
#include<assert.h>
using namespace std;
#define all(X) (X).begin(), (X).end()
#define rep(I,A,B) for(int I=(A);I<(B);I++)
#define repd(I,A,B) for(int I=(A);I>(B);I--)
#define sort_unique(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
typedef long long LL;
typedef pair<int,int> PII;
typedef pair<LL,LL> PLL;
typedef vector<int> VI;
typedef vector<PII> VPII;
typedef vector<LL> VLL;
typedef vector<PLL> VPLL;
VI range(int A, int B) { VI v; rep(i,A,B) v.push_back(i); return v;}
template<class T> void _R(T &x) { cin >> x; }
void _R(int &x) { scanf("%d", &x); }
void _R(int64_t &x) { scanf("%lld", &x); }
void _R(double &x) { scanf("%lf", &x); }
void _R(char &x) { scanf(" %c", &x); }
void _R(char *x) { scanf("%s", x); }
void R() {}
template<class T, class... U> void R(T &&head, U &&... tail) { _R(head); R(tail...); }
template<class T> void _W(const T &x) { cout << x; }
void _W(const int &x) { printf("%d", x); }
void _W(const int64_t &x) { printf("%lld", x); }
void _W(const double &x) { printf("%.16f", x); }
void _W(const char &x) { putchar(x); }
void _W(const char *x) { printf("%s", x); }
template<class T,class U> void _W(const pair<T,U> &x) {_W("{"); _W(x.first); putchar(','); _W(x.second); _W("}");}
template<class T> void _W(const vector<T> &x) { for (auto i = x.begin(); i != x.end(); _W(*i++)) if (i != x.cbegin()) putchar(' '); }
void W() { }
template<class T, class... U> void W(const T &head, const U &... tail) { _W(head); putchar(sizeof...(tail) ? ' ' : '\n'); W(tail...); }

int main()
{
    #ifdef DEBUG
    freopen("B-1.in","r",stdin);
    //freopen("tmp.out","w",stdout);
    #endif
    
    int t; R(t);
    while(t--) {
    	LL n,x,y; R(n,x,y);
    	rep(i,0,n) {
    		int a; R(a);
    		x^=a;
    	}
    	if(x%2==y%2) W("Alice");
    	else W("Bob");
    }

    return 0;
}

  • 11
    点赞
  • 10
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值