hdu 2873 Bomb Game (二维sg打表)
来源:互联网 发布:首届全球程序员节 编辑:程序博客网 时间:2024/06/05 11:41
Bomb Game
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 609 Accepted Submission(s): 290
Problem Description
John and Jack, two mathematicians, created a game called “Bomb Game” at spared time. This game is played on an n*m chessboard. A pair of integers (p, q) represents the grid at row p, column q. Some bombs were placed on the chessboard at the beginning. Every round, a player can choose to explode a bomb located at (p, q), and the exploded bomb will disappear. Furthermore:
If two bombs located at the same position or a bomb located at (1, 1), they will be exploded automatically without producing new bombs.
Two players play in turn, until one player cannot explode the bombs and loses the game.
John always plays first.
Now, we’ll give you an initial situation, and you should tell us who will win at last. Assume John and Jack are smart enough, and they always do the best choice.
2 2
.#
..
2 2
.#
.#
0 0
Sample Output
John
Jack
题意:给你一个
思路:我们将炸弹的位置当做石子堆的石子个数,我们首先看边界的情况,即只有一行或者一列的时候:假设当前炸弹处于
ac代码:
/* ***********************************************Author : AnICoo1Created Time : 2016-08-09-09.39 TuesdayFile Name : D:\MyCode\2016-8月\2016-8-9.cppLANGUAGE : C++Copyright 2016 clh All Rights Reserved************************************************ */#include<stdio.h>#include<math.h>#include<string.h>#include<stack>#include<set>#include<map>#include<queue>#include<vector>#include<iostream>#include<algorithm>#define MAXN 1010000#define LL long long#define ll __int64#define INF 0xfffffff#define mem(x,y) memset(x,(y),sizeof(x))#define PI acos(-1)#define eps 1e-8using namespace std;ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}ll lcm(ll a,ll b){return a/gcd(a,b)*b;}ll powmod(ll a,ll b,ll MOD){ll ans=1;while(b){if(b%2)ans=ans*a%MOD;a=a*a%MOD;b/=2;}return ans;}double dpow(double a,ll b){double ans=1.0;while(b){if(b%2)ans=ans*a;a=a*a;b/=2;}return ans;}//headchar str[110][110];int sg[110][110];int vis[3333];int getSG(int x,int y){ if(sg[x][y]!=-1) return sg[x][y]; mem(vis,0); for(int i=0;i<x;i++) { for(int j=0;j<y;j++) { vis[getSG(x,j)^getSG(i,y)]=1; } } for(int i=0;;i++) if(!vis[i]) return i;}void init(){ mem(sg,-1); for(int i=0;i<55;i++) sg[0][i]=sg[i][0]=i; for(int i=0;i<55;i++) for(int j=0;j<55;j++) sg[i][j]=getSG(i,j);}int main(){ int n,m;init(); while(scanf("%d%d",&n,&m)!=EOF,n||m) { for(int i=0;i<n;i++) scanf("%s",str[i]); int ans=0; for(int i=0;i<n;i++) { for(int j=0;j<m;j++) { if(str[i][j]=='#') { ans^=sg[i][j]; } } } if(ans) printf("John\n"); else printf("Jack\n"); } return 0;}
- hdu 2873 Bomb Game (二维sg打表)
- Bomb Game - HDU 2873 sg函数
- hdu2873 Bomb Game 二维SG博弈
- hdu 2873 Bomb Game
- hdu 2873 Bomb Game
- HDU 2873 Bomb Game
- HDU-2873 Bomb Game
- hdu 2873 Bomb Game
- hdu2873 Bomb Game-----sg
- HDU 1846 Brave Game 巴什博弈 SG打表
- HDU 1517 A Multiplication Game SG打表
- hdu 2873 Bomb Game 【博弈-预处理表】
- hdu 3622 bomb game
- hdu 3622 Bomb Game
- hdu 3622 Bomb Game
- hdu 3622 Bomb Game
- HDU-3622 Bomb Game
- HDU-3622 Bomb Game
- iOS开发 - 多线程之NSThread
- C#控制台基础 #define #undef的实例
- 【转载】 --python发送各类邮件的主要方法
- 数据结构实验之求二叉树后序遍历和层次遍历
- textView聊天输入框调整优化界面
- hdu 2873 Bomb Game (二维sg打表)
- 数据结构实验之二叉树四:还原二叉树
- 有关mysql的innodb_flush_log_at_trx_commit参数
- hdu5793——A Boring Question(快速幂+逆元)
- 求一个集合的所有子集问题
- 条款七:千万不要重载&&,||和,操作符
- 从零开始学习Gradle之一---初识Gradle
- Mob短信验证
- POJ 1579 Function Run Fun