山东省第八届省赛 A:Return of the Nim(尼姆+威佐夫)
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")
Sample Input
2 3 2 3 2 2 2 1
Sample Output
Sherlock Watson
Hint
题意:
题意:
2.在没有出现空堆的情况下,每次每人可从所有石堆中取相同个数的石子 (当然所取的个数不能超过石堆中所含最少石子的个数)
谁先取完谁赢。告诉你石堆的个数及每堆所含石子的个数,要求你输出胜利者的姓名
题解:
两堆:威佐夫博弈(不作详细解释)
大于两堆:尼姆博弈
代码:
#include <bits/stdc++.h>
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <vector>
#include <map>
#include <set>
#include <bitset>
#include <queue>
#include <deque>
#include <stack>
#include <iomanip>
#include <cstdlib>
using namespace std;
#define is_lower(c) (c>='a' && c<='z')
#define is_upper(c) (c>='A' && c<='Z')
#define is_alpha(c) (is_lower(c) || is_upper(c))
#define is_digit(c) (c>='0' && c<='9')
#define min(a,b) ((a)<(b)?(a):(b))
#define max(a,b) ((a)>(b)?(a):(b))
#define IO ios::sync_with_stdio(0);\
cin.tie();\
cout.tie();
#define For(i,a,b) for(int i = a; i <= b; i++)
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
const ll inf=0x3f3f3f3f;
;
const ll inf_ll=(ll)1e18;
const ll maxn=100005LL;
const ll mod=1000000007LL;
+;
int ans[N];
int main()
{
int T;
cin >> T;
while(T--)
{
int n;
cin >> n;
For(i, , n)
cin >> ans[i];
){
] > ans[])
swap(ans[], ans[]);
] - ans[]) * ((sqrt()+)/2.0));
])
cout<< "Watson"<< endl;
else
cout<< "Sherlock" <<endl;
} else {
;
For(i, , n)
res = res^ans[i];
)
cout<< "Watson" <<endl;
else
cout<< "Sherlock" <<endl;
}
}
;
}
山东省第八届省赛 A:Return of the Nim(尼姆+威佐夫)的更多相关文章
- 第八届河南省赛F.Distribution(水题)
10411: F.Distribution Time Limit: 1 Sec Memory Limit: 128 MB Submit: 11 Solved: 8 [Submit][Status] ...
- 第八届河南省赛G.Interference Signal(dp)
G.Interference Signal Time Limit: 2 Sec Memory Limit: 128 MB Submit: 35 Solved: 17 [Submit][Status ...
- 第八届河南省赛D.引水工程(kruthcra+prime)
D.引水工程 Time Limit: 2 Sec Memory Limit: 128 MB Submit: 118 Solved: 41 [Submit][Status][Web Board] D ...
- 第八届河南省赛C.最少换乘(最短路建图)
C.最少换乘 Time Limit: 2 Sec Memory Limit: 128 MB Submit: 94 Solved: 25 [Submit][Status][Web Board] De ...
- 第八届河南省赛B.最大岛屿(dfs)
B.最大岛屿 Time Limit: 1 Sec Memory Limit: 128 MB Submit: 30 Solved: 18 [Submit][Status][Web Board] De ...
- POJ-2421Constructing Roads,又是最小生成树,和第八届河南省赛的引水工程惊人的相似,并查集与最小生成树的灵活与能用,水过~~~
Constructing Roads Time Limit: 2000MS Memory Limit: 65536K Description There are N v ...
- 新疆大学ACM-ICPC程序设计竞赛五月月赛(同步赛)- chess(威佐夫博奕)
---恢复内容开始--- 链接:https://www.nowcoder.com/acm/contest/116/G来源:牛客网 题意:一个棋盘,老王和小人下棋,棋子只能往下或者往左或者往左下走,小人 ...
- 山东省第八届ACM省赛游记
Day 1: 凌晨,来了几分兴致,和队友在VJudge上开了一把zoj月赛,WA一发闷一口拿铁,一瓶拿铁 不一会就被喝完了!好气啊!遂开始愉快地打游戏,打着打着,woc,居然3点半了,小睡片 刻,咬上 ...
- 第十届山东省acm省赛补题(1)
今天第一场个人训练赛的题目有点恐怖啊,我看了半个小时多硬是一道都不会写.我干脆就直接补题去了.... 先补的都是简单题,难题等我这周末慢慢来吧... A Calandar Time Limit: 1 ...
随机推荐
- 子查询 做where条件 做 from的临时表 ,做select的一个字段 等
子查询 做where条件 做 from的临时表 ,做select的一个字段 等
- C#重载和重写
Overload:重载就是在同一个类中,方法名相同,参数列表不同.参数列表不同包括:参数的个数不同,参数类型不同. using System; using System.Collections.Gen ...
- CTSC2018 & APIO2018 颓废 + 打铁记
CTSC2018 & APIO2018 颓废 + 打铁记 CTSC 5 月 6 日 完美错过报道,到酒店领了房卡放完行李后直接奔向八十中拿胸牌.饭票和资料.试机时是九省联考的题,从来没做过,我 ...
- [洛谷P4015]运输问题
题目大意:有m个仓库和n个商店.第i个仓库有 $a_{i}$ 货物,第j个商店需要$b_{j}$个货物.从第i个仓库运送每单位货物到第j个商店的费用为$c_{i,j}$.求出最小费用和最大费用 题 ...
- Notice : brew install php70
To enable PHP in Apache add the following to httpd.conf and restart Apache: LoadModule php7_module ...
- VK Cup 2016 - Round 1 (Div. 2 Edition) A Bear and Reverse Radewoosh
A. Bear and Reverse Radewoosh time limit per test 2 seconds memory limit per test 256 megabytes inpu ...
- linux crontab执行shell脚本中包含相对路径的问题
实例一 test.sh文件 echo `date`>test.log 配置crontab 设置 */1 * * * * sh /data/test.sh 在/data/目录下,未找到test.l ...
- iconfont字体图标
1.1.进入阿里图标网站 http://www.iconfont.cn/ 1.2.在购物车里添加自己需要的字体图标 1.3.下载代码 1.4.解压过后,找到iconfont.css,放在你的项目里,需 ...
- 打砖块(codevs 1257)
题目描述 Description 在一个凹槽中放置了n层砖块,最上面的一层有n块砖,第二层有n-1块,……最下面一层仅有一块砖.第i层的砖块从左至右编号为1,2,……i,第i层的第j块砖有一个价值a[ ...
- HDU 5881--Tea 思维规律
感谢http://blog.csdn.net/black_miracle/article/details/52567718 题意:有一壶水, 体积在 L和 R之间, 有两个杯子, 你要把水倒到两个杯子 ...