题目描述
Hakase and Nano are playing an ancient pebble game (pebble is a kind of rock). There are n packs of pebbles, and the i-th pack contains ai pebbles. They take turns to pick up pebbles. In each turn, they can choose a pack arbitrarily and pick up at least one pebble in this pack. The person who takes the last pebble wins.
This time, Hakase cheats. In each turn, she must pick pebbles following the rules twice continuously.
Suppose both players play optimally, can you tell whether Hakase will win?
输入
The first line contains an integer T (1≤T≤20) representing the number of test cases.
For each test case, the fi rst line of description contains two integers n(1≤n≤106) and d (d = 1 or d = 2). If d = 1, Hakase takes first and if d = 2, Nano takes first. n represents the number of pebble packs.
The second line contains n integers, the i-th integer ai (1≤ai≤109) represents the number of pebbles in the i-th pebble pack.
输出
For each test case, print “Yes” or “No” in one line. If Hakase can win, print “Yes”, otherwise, print “No”.
样例输入
2
3 1
1 1 2
3 2
1 1 2
样例输出
Yes No
审题确实是大问题,要和队员交流完成,这个题就把犯规罚取两次看成了犯规等两次再取,不能太随意
#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;
int x[1000010];
int main()
{
int t;
scanf("%d",&t);
while(t--)
{
int a,b;
scanf("%d %d",&a,&b);
int c=0;
for(int i=0;i<a;i++)
{
scanf("%d",&x[i]);
if(x[i]==1)
{
c++;
}
}
if(b==1)
{
if(c==a&&a%3==0)
{
printf("No\n");
}
else
{
printf("Yes\n");
}
}
else
{
if((c==a&&a%3==1)||(c==a-1&&a%3==0)||(c==a-1&&a%3==1))
{
printf("No\n");
}
else
{
printf("Yes\n");
}
}
}
return 0;
}