Ural 1465. Pawn Game nim博弈
来源:互联网 发布:数据脱敏系统 编辑:程序博客网 时间:2024/06/14 08:05
1465. Pawn Game
Time limit: 1.0 second
Memory limit: 64 MB
Memory limit: 64 MB
In their free time, Santa Claus Petrovich and Santa Claus Egorych play the following game. Pawns are arranged on a board 3×3 in the following way:
Pawns move and attack according to the standard chess rules, and there is one additional rule: it is obligatory to attack. The one who cannot make a move loses. White moves first. For the last 100 years, Petrovich have been playing white and he always won. Once Egorych became tired of this and brought a board 3×5. But he again was losing constantly playing black. "What's the matter", he thought and decided to buy a board 3×N:
And here Petrovich has to think which color to play in order to win. Help him to decide.
Input
The integer N (1 ≤ N ≤ 109).
Output
"White" if Petrovich should play white, and "Black" if he should play black. Egorych and Petrovich always make moves according to their optimal strategies.
Samples
3
White
4
Black
5
White
Problem Author: Alexander Toropov
Problem Source: Ural SU Contest. Petrozavodsk Winter Session, January 2006
Problem Source: Ural SU Contest. Petrozavodsk Winter Session, January 2006
//nim博弈#include <iostream>using namespace std;int sg[100000];int a[10000];int b[1000]= {1,0,0,0,0,0,1,0,0,0,1};string m[2]= {"White","Black"};int c[10000];int main(){ sg[1]=1; sg[2]=1; int cnt=0; for(int i=3; i<=5000; i++) { a[sg[i-2]]=i; for(int j=0; j<=i-3; j++) a[(sg[j]^sg[i-j-3])]=i; for(int j=0; j<=i; j++) if(a[j]!=i) { sg[i]=j; break; } if(i>82) { c[cnt++]=sg[i]; } } int n; cin>>n; if(n<=82) { if(sg[n]) cout<<"White"<<endl; else cout<<"Black"<<endl; } else { n-=83; if(c[n%34]) cout<<"White"<<endl; else cout<<"Black"<<endl; }}
- Ural 1465. Pawn Game nim博弈
- URAL 1465 Pawn Game
- Ural 1465 Pawn Game
- Northcott Game + nim博弈
- hdu3389 Game NIM博弈
- hdu1730Northcott Game NIM博弈
- leetcode---Nim Game---博弈
- Nim Game 博弈游戏
- Northcott Game + 博弈 + nim博弈
- HDU 5011 Game nim博弈
- HDU5011 Game(Nim博弈)
- HDU 5011 Game 【Nim博弈】
- nim博弈 hdu3951 Coin Game
- Matrix Game (Nim博弈)
- HDU5011 Game(Nim博弈)
- Northcott Game (Nim博弈)
- URAL 1397 Points Game <博弈>
- HDOJ 3389 Game (博弈:Staircase Nim)
- TraceView issue
- codeforces 325A. Square and Rectangles
- window.onload=function(){}作用
- 为项目整合SSH2流程
- Linuxs初学者学习探秘总结
- Ural 1465. Pawn Game nim博弈
- 设计模式C++描述----05.职责链(Chain of Responsibility)模式
- pache commons开源工具简介
- duilib学习笔记
- android中使用dimen定义尺寸
- Ext.Ajax.request方法 参数
- jQuery冒泡
- 关于如何使用内容提供器Content Provider的简介
- MiniProfiler 安装与设置