poj 3575 Crosses and Crosses(SG函数)
| Time Limit: 3000MS | Memory Limit: 65536K | |
| Total Submissions: 3063 | Accepted: 1196 | |
| Case Time Limit: 2000MS | ||
Description
The game of Crosses and Crosses is played on the field of 1 × n cells. Two players make moves in turn. Each move the player selects any free cell on the field and puts a cross ‘×’ to it. If after the player’s move there are three crosses in a row, he wins.
You are given n. Find out who wins if both players play optimally.
Input
Input file contains one integer number n (3 ≤ n ≤ 2000).
Output
Output ‘1’ if the first player wins, or ‘2’ if the second player does.
Sample Input
| #1 | 3 |
|---|---|
| #2 | 6 |
Sample Output
| #1 | 1 |
|---|---|
| #2 | 2 |
Source
【思路】
SG函数,博弈
题目treblecross的简化。
【代码】
#include<cstdio>
#include<cstring>
using namespace std; const int N = +; int sg[N],n; int dfs(int x) {
if(x<=) return ;
if(sg[x]!=-) return sg[x];
int vis[N];
memset(vis,,sizeof(vis));
for(int i=;i<=x;i++)
vis[dfs(i-)^dfs(x-i-)]=;
for(int i=;;i++)
if(!vis[i]) return sg[x]=i;
} int main() {
memset(sg,-,sizeof(sg));
while(scanf("%d",&n)==) {
if(dfs(n)) puts("");
else puts("");
}
return ;
}
poj 3575 Crosses and Crosses(SG函数)的更多相关文章
- POJ 2311 Cutting Game(SG函数)
Cutting Game Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 4806 Accepted: 1760 Desc ...
- POJ 2960 S-Nim 博弈论 sg函数
http://poj.org/problem?id=2960 sg函数几乎是模板题. 调试代码的最大障碍仍然是手残在循环里打错变量名,是时候换个hydra产的机械臂了[超想要.jpg] #includ ...
- POJ 3537 Crosses and Crosses(sg博弈)
题目:在1*n 的棋盘里面,A和B都在里面画叉 , 如果谁可以画了一个叉后,可以连成3个叉,那谁胜利 : 分析: 首先考虑如果我在玩游戏,我最希望对手可以画出-x-x or -xx- , 这种 ...
- POJ 3537 Crosses and Crosses (NEERC)
Crosses and Crosses Time Limit: 3000MS Memory Limit: 65536K Total Submissions: 4 ...
- POJ 3537 Crosses and Crosses
Crosses and Crosses Time Limit: 3000MS Memory Limit: 65536K Total Submissions: 2237 Accepted: 821 Ca ...
- 【POJ】【3537】Crosses and Crosses
博弈论 相当于放了x的位置,左右4格都不能再放x了,谁无处可放就输. n<=2000 直接枚举后继状态,暴力求SG函数即可. 例: 0000000->x..0000 / .x..000 / ...
- POJ 2425 A Chess Game 博弈论 sg函数
http://poj.org/problem?id=2425 典型的sg函数,建图搜sg函数预处理之后直接求每次游戏的异或和.仍然是因为看不懂题目卡了好久. 这道题大概有两个坑, 1.是搜索的时候vi ...
- POJ 3537:Crosses and Crosses(Multi-Nim)
[题目链接] http://poj.org/problem?id=3537 [题目大意] 在一个1*n的方格纸上下棋,谁先连三子谁就赢了,问必胜的是谁. [题解] 我们发现对于一个n规模的游戏.在i位 ...
- POJ 2960 S-Nim (sg函数)
题目链接:http://poj.org/problem?id=2960 题目大意:给定数组S,接下来给出m个游戏局面.游戏局面是一些beads堆,先给出堆数,然后是每一堆中beads的数目.游戏规则是 ...
随机推荐
- Sqlserver 列转行 行转列
sqlserver的行转列 列转行问题 行转列:1 使用Case when 方式 CREATE TABLE [StudentScores]( [UserName] NVARCHAR(20), --学生 ...
- windows8一直更新不了的问题————解决方案
以下是微软官方工程师的详细解答: 尊敬的佐先生: 您好! 感谢您联系微软技术支持!我是微软技术支持工程师,我姓张.我将协助您解决有关问题.您的问题编号是SRX 1274238225 对于您当前的更新问 ...
- 将CString(unicode)转换为char*(ANSI)
1.将CString(unicode)转换为char*(ANSI) CString strServIP; pChat->GetDlgItemText(IDC_IP,strServIP); ] = ...
- js隔行变色
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...
- iOS: 学习笔记, 用代码驱动自动布局实例(swift)
iOS自动布局是设置iOS界面的利器.本实例展示了如何使用自动布局语言设置水平布局, 垂直布局1. 创建空白iOS项目(swift)2. 添加一个控制器类, 修改YYAppDelegate.swift ...
- Silverlight中在MVVM模式下对DatagridRow选择控件封装
在项目中,凡是涉及到表格的地方用的最多的控件,自然少不了DataGrid的身影,它明了的展示各种数据让人十分喜欢.现在要实现一个功能,使DataGrid具有全选和项选中的功能,如果在传统后台代码中完成 ...
- 《C和指针》章节后编程练习解答参考——第5章
5.1 题目: 略 解答代码: #include <stdio.h> int main(void) { char ch; while (((ch = getchar()) != EOF) ...
- iOS 中KVC、KVO、NSNotification、delegate 总结及区别-b
1.KVC,即是指 NSKeyValueCoding,一个非正式的Protocol,提供一种机制来间接访问对象的属性.而不是通过调用Setter.Getter方法访问.KVO 就是基于 KVC 实现的 ...
- scrollview 例子2
代码: #import "RootViewController.h" @implementation RootViewController @synthesize scrollVi ...
- Arrays.fill方法的陷阱
昨晚调试程序时发现的,该方法不能初始化二维数组,不过当时没有报CE,提交的时候也是WA:今早上单独测试该方法,也没有CE,不过运行时异常.切记