山东省第八届省赛A题 Return of the Nim
来源:互联网 发布:fifaaol3数据库 编辑:程序博客网 时间:2024/06/05 15:23
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
nim博弈和威佐夫博弈 n=2时用威佐夫博弈 剩余情况用nim博弈
#include<iostream>#include<cstdio>#include<cstring>#include<cmath>using namespace std;int a[123];int main(){ int t; scanf("%d",&t); while(t--) { int n; scanf("%d",&n); int flag=0; if(n==2) { int a,b; scanf("%d%d",&a,&b); if(a>b) swap(a,b); double e=(sqrt(5.0)+1.0)/(2.0); int k=b-a; int kk=(int)(k*e); if(kk==a) flag=1; } else { int i; int sum=0; for(i=0; i<=n-1; i++) { scanf("%d",&a[i]); sum^=a[i]; } if(sum==0) flag=1; } if(flag) printf("Watson\n"); else printf("Sherlock\n"); } return 0;}
0 0
- 山东省第八届省赛A题 Return of the Nim
- Return of the Nim----Nim博弈+威佐夫博弈 山东省第八届省赛A题
- 山东省第八届ACM省赛A.Return of the Nim
- 山东省第八届省赛 Return of the Nim(博弈)
- ACM 第八届山东省赛 A题 Return of the Nim
- SDUT 3893 (山东省第八届ACM省赛A题) Return of the Nim 博弈nim+威佐夫
- 2017第八届浪潮杯山东省赛 A.Return of the Nim 博弈
- 山东省第八届acm省赛 Return of the Nim
- 【补题】2017山东省赛A题 Return of the Nim
- Return of the Nim 山东省赛
- 省SD2017 A Return of the Nim【威佐夫博弈+NIM】
- Return of the Nim
- Return of the Nim
- 2017 省赛 山东 A Return of the Nim 【博弈】【Nim+Wythoff】
- sdut 3893 Return of the Nim(matrix nim)
- Nim博弈和威佐夫博弈 Return of the Nim
- 山东省第八届ACM省赛A题
- 山东省第7届省赛 E题 The Binding of Isaac
- 就是为了上传图片
- 0514 js基本概念
- Hibernate_又快又准的Hibernate映射技巧
- 忙着关电脑,拔网线的时候,你不好奇什么是“比特币”吗?
- 基于Dubbo框架构建分布式服务【续】
- 山东省第八届省赛A题 Return of the Nim
- Hadoop基础教程-第3章 HDFS:分布式文件系统(3.2 HDFS文件读写)
- 日志系统ELK使用详解(三)--elasticsearch安装
- Linux增加php扩展gd库
- pyhton+随机森林
- struts2 <s:iterator> status属性
- Window10+Python3.5安装opencv
- C语言与数字信号处理——正态分布的随机数
- 现代前端技术解析(3)