POJ
来源:互联网 发布:淘宝联盟2016旧版 编辑:程序博客网 时间:2024/06/15 09:50
题目:给你一个w*h的矩形,每次可以选择横向或纵向切割矩形,将其分成2个矩形,N次操作后,就会有N+1个矩形,谁先切割出1*1谁就获胜。
思路:谁先切割出1*1谁就胜,那么就是说谁切割出1*x或x*1谁就输了。然后求SG函数就可以了。
代码:
#pragma comment(linker, "/STACK:1024000000,1024000000")#include<iostream>#include<algorithm>#include<ctime>#include<cstdio>#include<cmath>#include<cstring>#include<string>#include<vector>#include<map>#include<set>#include<queue>#include<stack>#include<list>#include<numeric>using namespace std;#define LL long long#define ULL unsigned long long#define INF 0x3f3f3f3f#define mm(a,b) memset(a,b,sizeof(a))#define PP puts("*********************");template<class T> T f_abs(T a){ return a > 0 ? a : -a; }template<class T> T gcd(T a, T b){ return b ? gcd(b, a%b) : a; }template<class T> T lcm(T a,T b){return a/gcd(a,b)*b;}// 0x3f3f3f3f3f3f3f3f//0x3f3f3f3fconst int maxn=210;int sg[maxn][maxn];int get_sg(int w,int h){ if(w>h) swap(w,h); if(sg[w][h]!=-1) return sg[w][h]; bool mex[1000]; mm(mex,false); for(int i=2;i<=w;i++){ if(w-i>=2){ int pos=(get_sg(i,h)^get_sg(w-i,h)); mex[pos]=true; } } for(int i=2;i<=h;i++){ if(h-i>=2){ int pos=(get_sg(w,i)^get_sg(w,h-i)); mex[pos]=true; } } for(int i=0;;i++){ if(!mex[i]){ sg[w][h]=i; break; } } return sg[w][h];}int main(){ int w,h; mm(sg,-1); while(~scanf("%d%d",&w,&h)){ int ans=get_sg(w,h); if(ans>0) printf("WIN\n"); else printf("LOSE\n"); } return 0;}
阅读全文
0 0
- POJ
- poj
- POJ
- POJ
- poj
- poj
- POJ
- POJ
- poj
- POJ
- POJ
- POJ
- POJ
- POJ
- POJ
- POJ
- POJ
- POJ
- Eclipse与Android Studio添加依赖的方法
- C语言字符串读写函数
- git出现 Warning: the ECDSA host key for 'myserver' differs from the key for the IP address 192.。
- 欢迎使用CSDN-markdown编辑器
- RabbitMQ基础信息详解
- POJ
- 高逼格之String... 的写法
- 求Sn=a+aa+aaa+aaaa+aaaaa的前5项之和,其中a是一个数字,例如:2+22+222+2222+22222
- Oracle ORA-39726压缩表删除字段处理方法
- shell中各种括号的作用()、(())、[]、[[]]、{}
- 视图矩阵的推导(1)
- 【POCO】POCO学习总结(二)——配置选择
- 数据库访问工具 DBUtl
- 20170928链接