hdu3404 Switch lights
来源:互联网 发布:java 日志slj4j 编辑:程序博客网 时间:2024/06/16 05:45
Switch lights
Time Limit: 6000/3000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 341 Accepted Submission(s): 180
Problem Description
lxhgww is playing a game with his computer Deep Blue.
The game is played on a matrix containing lights. At first, some lights are on, while others are off. lxhgww and Deep Blue take turns to switch the lights. For each step, the player should choose a rectangle in the matrix: (x1 , y1) , (x1 , y2) , (x2 , y1) , (x2 , y2) , (x1<=x2,y1<=y2, the light at (x2, y2) should be on) and change the lights’ status on the four vertex of the rectangle, namely on to off, and off to on. The player turns all the lights off wins the game. Notice the rectangle is possibly degenerated to line or even a single cell so that the player may also switch two or one besides four lights in a move.
Deep Blue's strategy is perfect, if it has a chance to win, never will it lose. Does lxhgww have a chance to win if he takes the first step?
The game is played on a matrix containing lights. At first, some lights are on, while others are off. lxhgww and Deep Blue take turns to switch the lights. For each step, the player should choose a rectangle in the matrix: (x1 , y1) , (x1 , y2) , (x2 , y1) , (x2 , y2) , (x1<=x2,y1<=y2, the light at (x2, y2) should be on) and change the lights’ status on the four vertex of the rectangle, namely on to off, and off to on. The player turns all the lights off wins the game. Notice the rectangle is possibly degenerated to line or even a single cell so that the player may also switch two or one besides four lights in a move.
Deep Blue's strategy is perfect, if it has a chance to win, never will it lose. Does lxhgww have a chance to win if he takes the first step?
Input
The first line is an integer T(T<=100) indicating the case number.
Each case has one integers n (n<= 1000 ), the number of on-lights at the beginning of the game.
Then come n lines, each line has two integers, xi , yi, (1<=xi<=10000, 1<=yi<=10000) , so light at (xi, yi) is on at first. (No two lights at the same position)
Each case has one integers n (n<= 1000 ), the number of on-lights at the beginning of the game.
Then come n lines, each line has two integers, xi , yi, (1<=xi<=10000, 1<=yi<=10000) , so light at (xi, yi) is on at first. (No two lights at the same position)
Output
If lxhgww still has a chance to win, output "Have a try, lxhgww.", otherwise tell lxhgww "Don't waste your time."
Sample Input
221 22 121 12 2
Sample Output
Don't waste your time.Have a try, lxhgww.坑啊,这题不好做,推荐看从“k 倍动态减法游戏”出发探究一类组合游戏问题这篇论文,很详细,但是不好懂!#include <iostream>#include <stdio.h>#include <string.h>using namespace std;int pri[2][2]={0,0,0,1};int get(int x,int y){ if(x<2)return pri[x][y]; int i,p,t,s,m; for(i=0;;i++){ if(((1<<(1<<i))<=x)&&(x<(1<<(1<<(i+1))))) break; } m=1<<(1<<i); p=x/m,s=y/m,t=y-s*m; int c1=get(p,s); int c2=get(p,t); return m*(c1^c2)^get(m/2,c1);}int getsg(int x,int y){ if(x<y)return getsg(y,x); if(x<2)return pri[x][y]; int i,p,t,s,q,m; for(i=0;;i++){ if(((1<<(1<<i))<=x)&&(x<(1<<(1<<(i+1))))) break; } m=1<<(1<<i); p=x/m,q=x-p*m,s=y/m,t=y-s*m; int c1=getsg(p,s); int c2=getsg(p,t)^getsg(q,s); int c3=getsg(q,t); return m*(c1^c2)^c3^get(m/2,c1);}int main(){ int tcase,i,x,y,ans,n; scanf("%d",&tcase); while(tcase--){ scanf("%d",&n); for( i=0,ans=0;i<n;i++){ scanf("%d%d",&x,&y); ans^=getsg(x,y); } if(ans)printf("Have a try, lxhgww.\n"); else printf("Don't waste your time.\n"); } return 0;}
- hdu3404 Switch lights
- hdu3404 Switch lights-----NIM积
- hdu3404 Switch lights 求NIM积
- hdu 3404 Switch lights
- HDU 3404 Switch lights (NIM 积)
- HDU-3404 Switch lights(NIM积)
- CS 300 Switch the Lights 观察+前缀差分
- Lights
- Lights
- switch
- Switch
- Switch
- switch
- switch
- switch
- Switch
- switch
- switch
- C++智能指针auto_ptr
- UVa 1423 Guess (拓扑排序)
- cocos2dx 2.1.4 shader解析-1
- CAP理论十二年回顾:"规则"变了
- 使用SGD(Stochastic Gradient Descent)进行大规模机器学习
- hdu3404 Switch lights
- In-Stream大数据处理模式
- 1022. Digital Library (30)
- 用 NDK 编译 ffmpeg 到 Android 平台
- linux避免进程随终端关闭而被关闭
- In-Stream Big Data Processing
- poj 3041 Asteroids 二分图匹配
- Understanding GC pauses in JVM, HotSpot's minor GC.
- 国标645协议.....2007---项目所需二(数据链路层)