1457: 棋盘游戏
来源:互联网 发布:windows连不上无线网 编辑:程序博客网 时间:2024/05/29 04:51
1457: 棋盘游戏
Time Limit: 5 Sec Memory Limit: 64 MBSubmit: 327 Solved: 185
[Submit][Status][Discuss]
Description
有一个100 * 100的棋盘,其中左下角的编号为(0, 0), 右上角编号为(99, 99)。棋盘上有N个Queen,最开始第i个Queen的位置为(Xi, Yi)。现在有两个玩家依次来操作,每一次一个玩家可以选择其中一个Queen,将它跳到(Xi – k, Yi)或(Xi, Yi - k)或(Xi – k, Yi - k), 其中k > 0。注意在游戏的过程中,一个格子里面可能出现多个Queen。如果谁先将任意一个Queen移动到(0, 0), 谁就获胜。问先手必胜还是后手必胜?
Input
注意本题是多组数据。 第一行有一个数T, 表示数据组数。 接下来有T组数据,每组数据的第一行一个正整数N表示Queen的个数。接下来N行每行两个数表示第i个Queen的初始位置Xi, Yi(0 <= Xi <= 99, 0 <= Yi <= 99)。
Output
对于每一组数据,你需要输出是先手必胜还是后手必胜。 如果是先手必胜,输出“^o^“, 如果是后手必胜,输出”T_T”。
Sample Input
2
2
3 4
3 5
3
3 2
4 2
3 1
2
3 4
3 5
3
3 2
4 2
3 1
Sample Output
^o^
T_T
数据范围
T <= 10, N <= 1000
T_T
数据范围
T <= 10, N <= 1000
HINT
Source
#include<iostream>#include<cstdio>#include<algorithm>#include<cmath>#include<cstring>#include<vector>#include<queue>#include<set>#include<map>#include<stack>#include<bitset>#include<ext/pb_ds/priority_queue.hpp>using namespace std; const int N = 100; int T,n,cnt,sg[N][N],bo[N*N];bool vis[N][N]; void Dfs(int x,int y){ if (vis[x][y]) return; stack <int> s; vis[x][y] = 1; for (int k = 1; k < x; k++) if (x - k != y) Dfs(x - k,y),s.push(sg[x - k][y]); for (int k = 1; k < y; k++) if (y - k != x) Dfs(x,y - k),s.push(sg[x][y - k]); for (int k = 1; k < min(x,y); k++) Dfs(x - k,y - k),s.push(sg[x - k][y - k]); ++cnt; while (!s.empty()) bo[s.top()] = cnt,s.pop(); for (int i = 0; ; i++) if (bo[i] != cnt) {sg[x][y] = i; return;}} void Check(){ scanf("%d",&n); int sum; bool flag; sum = flag = 0; while (n--) { int x,y; scanf("%d%d",&x,&y); if (!x || !y || x == y) flag = 1; else sum ^= sg[x][y]; } puts(flag || sum ? "^o^" : "T_T");} int main(){ #ifdef DMC freopen("DMC.txt","r",stdin); #endif vis[1][2] = vis[2][1] = 1; for (int i = 1; i <= 99; i++) for (int j = 1; j <= 99; j++) if (i != j) Dfs(i,j); cin >> T; while (T--) Check(); return 0;}
0 0
- 1457: 棋盘游戏
- bzoj 1457 棋盘游戏
- 【博弈】【bzoj 1457】: 棋盘游戏
- 棋盘游戏
- 棋盘游戏
- 棋盘游戏
- 棋盘游戏
- 棋盘游戏
- 棋盘游戏
- 棋盘游戏
- 棋盘游戏
- BZOJ 1457 棋盘游戏 SG函数
- BZOJ 1457 棋盘游戏 SG函数
- bzoj 1457: 棋盘游戏 sg函数
- BZOJ 1457: 棋盘游戏 SG函数
- hdu 1281棋盘游戏
- hdoj 1281 棋盘游戏
- hdu 1281 棋盘游戏
- 机器学习笔记3——牛顿方法
- 1.13接口卡
- 4月4日,Decode,每日20行。
- B/S(Web)实时通讯解决方案
- there is no staged files
- 1457: 棋盘游戏
- Android 最火的快速开发框架AndroidAnnotations使用详解
- 前端大牛得到的最佳职业生涯建议
- 网络层--地址解析协议ARP
- 1.14各类存储器芯片
- MySQL的3种应用方式和3种数据库用途
- Android冷启动白屏黑屏处理
- Java实现的矩阵类及矩阵的转置,加减乘和矩阵求逆
- 记录Building an MFC project for a non-Unicode character set is deprecated