poj解题报告——3537
来源:互联网 发布:nginx禁止代理ip访问 编辑:程序博客网 时间:2024/06/15 01:11
题意
有个2人玩的游戏在一个规模为1*n的棋盘上进行,每次一个人选择一个地方画上'X',一旦某个人画上X后出现了连续3个X,那么这个人就赢了。给n(3≤n≤=2000)问谁会赢。
题解考虑到如果画上一个X,就会有临近区域不能画X,也就是下一个人能画X的区域就变了,那么问题可以转换为谁不能画X谁就输了。
接着考虑每次画X的转移情况,最简单的就是画最左边的1~3个格子,这时剩下还有n-3~n-5个连续区域能画;如果画在4~n-3位置,就会把原问题分成两个子问题,都是SG博弈问题,所以直接求两者异或就行了。
#include<cstdio>#include<cstring>#include<iostream>using namespace std;int sg[2005];bool temp[2005];int main(){ sg[0]=0; sg[1]=1; sg[2]=1; sg[3]=1; sg[4]=2; sg[5]=2; for(int i=6;i<=2000;i++) { memset(temp,0,sizeof(temp)); temp[sg[i-3]]=temp[sg[i-4]]=temp[sg[i-5]]=1; for(int j=1;j<=i-5-j;j++) temp[sg[j]^sg[i-5-j]]=1; for(int j=0;j<=2000;j++) if(!temp[j]) { sg[i]=j; break; } } int n; while(scanf("%d",&n)!=EOF) { printf("%d\n",sg[n]?1:2); } return 0;}
0 0
- poj解题报告——3537
- POJ 1088 滑雪——解题报告
- POJ 1047——解题报告
- poj解题报告——poj1006
- poj解题报告——1032
- poj解题报告——1061
- poj解题报告——1450
- poj解题报告——1002
- poj解题报告——2109
- poj解题报告——1218
- poj解题报告——1250
- poj解题报告——1012
- poj解题报告——3299
- poj解题报告——2209
- poj解题报告——2406
- poj解题报告——2242
- poj解题报告——1401
- poj解题报告——1328
- Effective Objective-C 2.0 第2条:在类的头文件中尽量少引入其它头文件
- 如何获取Input标签自定义属性的值
- jQuery动画入门--顺序执行
- Objective-C语法之代码块(block)的使用
- 平方根的异常
- poj解题报告——3537
- 如何在android 系统 C/C++ 层中添加 log 信息
- 【图像配准】基于灰度的模板匹配算法(二):局部灰度值编码
- AE开发之路(三)
- POJ 1067 取石子游戏 (威佐夫博弈)
- ubuntu下安装Python的MySql的开发环境
- Hive Metastore canary创建数据库失败
- __attribute__((visibility("default")))
- POJ 3259 Wormholes 【SPFA 判断负环】