山东省第八届省赛 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 ...
随机推荐
- SQLAlchemy技术文档(中文版)(上)
在学习SQLAlchemy的过程中,好多时候需要查官方Tutorial,发现网上并没有完整的中文版,于是利用这两天空余时间粗略翻译了一下. 翻译效果很差....但也算是强迫自己通读一遍Tutorial ...
- 【bzoj1257】[CQOI2007]余数之和sum 数论
题目描述 给出正整数n和k,计算j(n, k)=k mod 1 + k mod 2 + k mod 3 + … + k mod n的值,其中k mod i表示k除以i的余数.例如j(5, 3)=3 m ...
- P2161 [SHOI2009]会场预约
题目描述 PP大厦有一间空的礼堂,可以为企业或者单位提供会议场地.这些会议中的大多数都需要连续几天的时间(个别的可能只需要一天),不过场地只有一个,所以不同的会议的时间申请不能够冲突.也就是说,前一个 ...
- 【题解】HAOI2008木棍分割
对于这道题目的两问,第一问直接二分答案求出最短长度.关键在于第二问应当如何求:建立dp方程,dp[i][j]代表到第i个分界线,切了j次(强制在第i处切一刀.这样就不会对后面的状态产生影响).状态转移 ...
- luogu P2764 最小路径覆盖问题
题目描述 给定有向图G=(V,E).设P 是G 的一个简单路(顶点不相交)的集合.如果V 中每个顶点恰好在P 的一条路上,则称P是G 的一个路径覆盖.P 中路径可以从V 的任何一个顶点开始,长度也是任 ...
- [Leetcode] Reverse nodes in k group 每k个一组反转链表
Given a linked list, reverse the nodes of a linked list k at a time and return its modified list. If ...
- 2017福建省赛 FZU2272~2283
1.FZU2272 Frog 传送门:http://acm.fzu.edu.cn/problem.php?pid=2272 题意:鸡兔同笼通解 题解:解一个方程组直接输出就行 代码如下: #inclu ...
- nginx实时生成缩略图到硬盘上
现在随着各终端的出现(手机,ipad等平板),以及各种终端的手机分辨率和尺寸都不同,现在手机用户流量都是宝,网上出现了各种各样的生成缩略图功能的架构,有使用php实时生成缩略图的,也有用nginx + ...
- 转:RBAC权限控制
名词解释: RBAC:Role-Based Access Control,基于角色的访问控制 关键词: RBAC,Java Shiro,Spring Security, 一. RBAC 要解决 ...
- jsp小知识点(2)
一:自定义的函数库:在wh.tld中 <description>JSTL 1.1 functions library</description> <display-nam ...