山东省第八届省赛 Return of the Nim(博弈)
来源:互联网 发布:蝙蝠侠 超人 知乎 编辑:程序博客网 时间:2024/05/20 10:14
Problem Description
Sherlock and Watson are playing the following modified version of Nim game:
- There are n piles of stones denoted as ,,...,, and n is a prime number;
- Sherlock always plays first, and Watson and he move in alternating turns. During each turn, the current player must perform either of the following two kinds of moves:
- Choose one pile and remove k(k >0) stones from it;
- Remove k stones from all piles, where 1≤k≤the size of the smallest pile. This move becomes unavailable if any pile is empty.
- Each player moves optimally, meaning they will not make a move that causes them to lose if there are still any better or winning moves.
Giving the initial situation of each game, you are required to figure out who will be the winner
Input
The first contains an integer, g, denoting the number of games. The 2×g subsequent lines describe each game over two lines:
1. The first line contains a prime integer, n, denoting the number of piles.
2. The second line contains n space-separated integers describing the respective values of ,,...,.
- 1≤g≤15
- 2≤n≤30, where n is a prime.
- 1≤pilesi≤ where 0≤i≤n−1
Output
For each game, print the name of the winner on a new line (i.e., either "Sherlock
" or "Watson
")
Example Input
232 3 222 1
Example Output
SherlockWatson
博弈题,在n<3的时候是威佐夫博弈,n>=3的时候是尼姆博弈,分类讨论完美解决。
Sherlock and Watson are playing the following modified version of Nim game:
- There are n piles of stones denoted as ,,...,, and n is a prime number;
- Sherlock always plays first, and Watson and he move in alternating turns. During each turn, the current player must perform either of the following two kinds of moves:
- Choose one pile and remove k(k >0) stones from it;
- Remove k stones from all piles, where 1≤k≤the size of the smallest pile. This move becomes unavailable if any pile is empty.
- Each player moves optimally, meaning they will not make a move that causes them to lose if there are still any better or winning moves.
Giving the initial situation of each game, you are required to figure out who will be the winner
The first contains an integer, g, denoting the number of games. The 2×g subsequent lines describe each game over two lines:
1. The first line contains a prime integer, n, denoting the number of piles.
2. The second line contains n space-separated integers describing the respective values of ,,...,.
- 1≤g≤15
- 2≤n≤30, where n is a prime.
- 1≤pilesi≤ where 0≤i≤n−1
For each game, print the name of the winner on a new line (i.e., either "Sherlock
" or "Watson
")
232 3 222 1
SherlockWatson
博弈胜利的条件是拿到最后的石子,所以只要判断谁先能让石子达到奇异状态谁就会获胜。
因为任何自然数在威佐夫博弈中都包含于唯一一个奇异状态中,所以只要两堆石子初始状态下处于非奇异状态,那么,先手胜,反之,后手胜。所以两堆是只要判断是否初始奇异即可。
三堆或者三堆以上时,是尼姆博弈,如果我们面对的是一个非奇异局势(a,b,c),要如何变为奇异局势呢?假设 a < b< c,我们只要将 c 变为 a^b,即可,因为有如下的运算结果: a^b^(a^b)=(a^a)^(b^b)=0^0=0。要将c 变为a^b,只从 c中减去 c-(a^b)。
而判断是否为奇异状态,只要用异或运算便可求得。
#include#include using namespace std; int a[1000]; int main(){ int t; scanf("%d",&t); while(t--){ int n; scanf("%d",&n); for(int i=0;i
阅读全文
0 0
- 山东省第八届省赛 Return of the Nim(博弈)
- Return of the Nim----Nim博弈+威佐夫博弈 山东省第八届省赛A题
- SDUT 3893 (山东省第八届ACM省赛A题) Return of the Nim 博弈nim+威佐夫
- 山东省第八届省赛A题 Return of the Nim
- 2017第八届浪潮杯山东省赛 A.Return of the Nim 博弈
- 山东省第八届ACM省赛A.Return of the Nim
- 山东省第八届acm省赛 Return of the Nim
- Return of the Nim 山东省赛
- ACM 第八届山东省赛 A题 Return of the Nim
- Nim博弈和威佐夫博弈 Return of the Nim
- 省SD2017 A Return of the Nim【威佐夫博弈+NIM】
- Return of the Nim
- Return of the Nim
- Return of the Nim----博弈(2017山东ACM-ICPC省赛)
- 2017 省赛 山东 A Return of the Nim 【博弈】【Nim+Wythoff】
- 【补题】2017山东省赛A题 Return of the Nim
- sdut 3893 Return of the Nim(matrix nim)
- hdu4994Revenge of Nim(博弈)
- 数据库增删改查!
- Chrome基本JS调试
- Make Menuconfig详解
- 机器学习算法(三)支持向量机
- ARP与ARP脚本
- 山东省第八届省赛 Return of the Nim(博弈)
- 实验吧ctf
- [bzoj1647][Usaco2007 Open]Fliptile 翻格子游戏
- WebSocket
- git 版本回退
- Java学习之路第十一天
- JAVA反射机制的一些用法
- startactivityforresult的使用,和singleTask不能使用的问题
- bzoj1497: [NOI2006]最大获利
原创粉丝点击
热门IT博客
热门问题
老师的惩罚
人脸识别
我在镇武司摸鱼那些年
重生之率土为王
我在大康的咸鱼生活
盘龙之生命进化
天生仙种
凡人之先天五行
春回大明朝
姑娘不必设防,我是瞎子
多尔衮与孝庄皇后
孝庄秘史主题曲
孝庄皇后简介
孝庄为什么叫大玉儿
孝庄秘史全集免费观看
孝庄和多尔衮
孝庄秘史演员表
多尔衮揉孝庄大白兔
孝庄和多尔衮睡过没
孝庄与多尔衮
清朝孝庄皇后简介
孝庄秘史免费观看完整
多尔衮和孝庄
孝庄秘史主题曲你
洪承畴大干孝庄
康熙生母被孝庄害死
孝庄秘史片尾曲
孝庄太后简介
孝庄为什么陷害容妃
多尔衮干孝庄皇后
为什么孝庄讨厌海兰珠
孝庄和多尔衮床上
孝庄皇后和多尔衮
你屠洪刚孝庄秘史主题曲mp3
孝庄秘史歌曲
孝庄秘史多尔衮
孝庄皇太后陵墓
孝庄秘史主题曲你屠洪刚唱
孝庄之小家碧玉
孝庄秘史图片
皇太极为什么不喜欢孝庄
孝廉
孝廉的意思
孝廉文化
qq三国推举孝廉
孝弟
孝德
孝德手抄报
孝德文化
孝德学校
孝德诗歌