跳到正文

题解

题解 P4702 【取石子】

Red_Bands_whk约 1 分钟
原文
文章信息与版本

文章信息

发布
2018年10月4日
收录
2026年11月29日
更新
2026年11月29日
篇幅
约 1 分钟
获赞
5
题目
P4702

版本

  1. v1当前

这题可以采用异或的思想。

之前做过类似的问题求解。

这样做能保证答案正确。

类似的题目都可以使用。

C++
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n;
	int x=0;
	cin >> n;
	for (int i=1; i<=n; i++)
	{
		 int y;
		 cin >> y;//输入
		 x^=y;//异或
	}
	if (x%2==1) cout << "Alice";
	else cout << "Bob";//输出
}
原文
抓取于
  1. HappyDavid

    C++好像也能用xor异或吧?

  2. Red_Bands_whk

    C++中异或是^,pascal是xor .若x是二进制数0101,y是二进制数1011; 则x⊕y=1110

  3. StarLbright40

    emm请问楼主能讲解一下异或怎么用吗