2016多校训练#1 1002 组合博弈
2016-08-06 18:19
465 查看
对于一开始接触博弈论的同学来说,这道题的思路略难,但是如果想到了把1*20的棋盘想象成一个20位的二进制数,然后通过sg函数预处理得到每一个二进制数相应的sg'值,最后直接用每一行的sg值相亦或即可。注意mex数组,也就是vis数组可以开得大一些,在没有确定sg'函数值范围的情况下:
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 1715 Accepted Submission(s): 748
Problem Description
Alice and Bob are playing a special chess game on an n × 20 chessboard. There are several chesses on the chessboard. They can move one chess in one turn. If there are no other chesses on the right adjacent block of the moved chess, move the chess to its right
adjacent block. Otherwise, skip over these chesses and move to the right adjacent block of them. Two chesses can’t be placed at one block and no chess can be placed out of the chessboard. When someone can’t move any chess during his/her turn, he/she will lose
the game. Alice always take the first turn. Both Alice and Bob will play the game with the best strategy. Alice wants to know if she can win the game.
Input
Multiple test cases.
The first line contains an integer T(T≤100),
indicates the number of test cases.
For each test case, the first line contains a single integer n(n≤1000),
the number of lines of chessboard.
Then n lines,
the first integer of ith line is m(m≤20),
indicates the number of chesses on the ith line of the chessboard. Then m integers pj(1≤pj≤20)followed,
the position of each chess.
Output
For each test case, output one line of “YES” if Alice can win the game, “NO” otherwise.
Sample Input
2
1
2 19 20
2
1 19
1 18
Chess
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 1715 Accepted Submission(s): 748
Problem Description
Alice and Bob are playing a special chess game on an n × 20 chessboard. There are several chesses on the chessboard. They can move one chess in one turn. If there are no other chesses on the right adjacent block of the moved chess, move the chess to its right
adjacent block. Otherwise, skip over these chesses and move to the right adjacent block of them. Two chesses can’t be placed at one block and no chess can be placed out of the chessboard. When someone can’t move any chess during his/her turn, he/she will lose
the game. Alice always take the first turn. Both Alice and Bob will play the game with the best strategy. Alice wants to know if she can win the game.
Input
Multiple test cases.
The first line contains an integer T(T≤100),
indicates the number of test cases.
For each test case, the first line contains a single integer n(n≤1000),
the number of lines of chessboard.
Then n lines,
the first integer of ith line is m(m≤20),
indicates the number of chesses on the ith line of the chessboard. Then m integers pj(1≤pj≤20)followed,
the position of each chess.
Output
For each test case, output one line of “YES” if Alice can win the game, “NO” otherwise.
Sample Input
2
1
2 19 20
2
1 19
1 18
#pragma comment(linker, "/STACK:1024000000,1024000000") #include<iostream> #include<cstdlib> #include<cstdio> #include<cmath> #include<cstring> #include<vector> #include<map> #include<algorithm> #include<queue> #include<stack>//博弈论,求sg函数,难题 using namespace std; int sg[1<<21]; int bit[40]; int vis[100];//vis数组尽量开大,防止数组越界 //棋子在走的过程中,二进制的数是递减的,因此可以利用之前数组存的值 //来降低时间复杂度~ int g(int x)//sg函数 { if(sg[x] != -1) return sg[x]; memset(vis, 0, sizeof(vis)); int cnt = 0; int tt = x; while(x) { bit[++cnt] = x%2; x /= 2; } int pos = -1; for(int i = 1; i <= cnt; i++) { if(bit[i] == 1 && pos != -1) vis[sg[tt+(1<<(pos-1))-(1<<(i-1))]] = 1;//注意细节。。 else if(bit[i] == 0) pos = i;//求最左边有效的0的位置 } for(int i = 0; i < 100; i++)//记住,这里要从0开始!! if(!vis[i]) return i; } void init() { sg[1] = sg[0] = 0; for(int i = 2; i < (1<<20); i++) sg[i] = g(i); } int main() { int t; memset(sg, -1, sizeof(sg)); init(); scanf("%d", &t); while(t--) { int n, ans = 0; scanf("%d", &n); for(int i = 1; i <= n; i++) { int m, sum = 0; scanf("%d", &m); while(m--) { int a; scanf("%d", &a); sum += (1<<(20-a));//把棋盘看成二进制数 } ans ^= sg[sum]; } if(ans == 0) printf("NO\n"); else printf("YES\n"); } return 0; }
相关文章推荐
- 2016多校训练Contest6: 1002 A Simple Chess hdu5794
- 2016多校训练Contest9: 1002 Best Division hdu5845
- 2016 多校最后一题 (HDU 5724) Chess (组合博弈)
- HDU 5858 Hard problem (2016 多校训练#10 1002)
- 2016多校训练Contest10: 1002 Hard problem hdu5858
- 2016多校训练Contest4: 1012 Bubble Sort hdu5775
- 2016多校训练Contest7: 1008 Hearthstone hdu5816
- 2015--多校训练第5场 1002 1005 1007
- 【2016杭电女生赛1002】【排列组合 隔板法】Desert 对n做正整序列拆分的方案数
- HDOJ 5738 (2016多校联合训练 Training Contest 2) Eureka
- 2016多校训练Contest5: 1012 World is Exploding hdu5792
- 2016多校训练Contest5: 1001 ATM Mechine hdu5781
- hdu 5782 Cycle (2016多校第五场1002) 后缀数组
- HDU5810(2016多校第七场)——Balls and Boxes(组合数学,概率)
- 2016 Multi-University Training Contest 8(2016多校训练第八场)1011
- 2016多校训练Contest9: 1012 Less Time, More profit hdu5855
- 2016 Multi-University Training Contest 2(2016多校训练第二场)1009
- [HDU5764] After a Sleepless Night [2016 Multi-University Training Contest 4(2016多校联合训练4) B]
- 2016多校联合训练contest4 1012Bubble Sort
- 2016多校训练Contest6: 1001 A Boring Question hdu5793