Test instructions
There were two people taking stones from a heap of n stones, one of whom could take two times, and the second one could only be taken once. Finally, the man who finished the victory.
Ideas:
type |
Hakase First |
after Hakase |
1 |
W |
L |
1 1 |
W |
W |
1 1 1 (3n) |
L |
W |
1 1 1 1 (3n+1) |
W |
L |
1 1 1 1 1 (3n+2) |
W |
W |
type |
Hakase First |
after Hakase |
X 1 1 |
W |
L |
X Y 1 |
W |
W |
X Y Z |
W |
W |
X 1 1 1 |
W |
L |
X Y 1 1 |
W |
W |
X Y Z 1 |
W |
W |
X 1 1 1 1 |
W |
W |
X Y 1 1 1 |
W |
W |
1. If n = 3t, if each stone heap is 1,a the initiator must lose (1 1 1). There is only one stone heap with a quantity greater than 1, then B initiator a must lose (X 1 1).
2. If n = 3t+1, if only a bunch of persimmon is greater than 1 (X 1 1 1). Then B initiator a must lose.
Write the code according to the conclusion:
Code:
#include<iostream>using namespace std;int main() { int t, n, d; scanf("%d", &t); while(t--) { bool flag = true; int cnt = 0, a; scanf("%d %d", &n, &d); for(int i = 0; i < n; i++) { scanf("%d", &a); if(a >= 2) cnt++; } int x = n % 3; if(x == 0) { if(cnt==0 && d==1) flag = false; if(cnt==1 && d==2) flag = false; }else if(x == 1){ if(cnt<=1 && d==2) flag = false; } if(flag) printf("Yes\n"); else printf("No\n"); } return 0;}
Hdu-6266-hdu 6266 Hakase and Nano (game theory)