山东省第八届省赛 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 ...
随机推荐
- vue2.0中vue-router使用总结
#在vue-cli所创建的项目中使用 进入到项目的目录后使用 npm install vue-router --save 安装vue-router,同时保存在webpack.Json配置文件中,然 ...
- Delphi 检查文件是否存在
Delphi下检查文件是否存在,我们可以使用FileExists函数 其原形如下: Function FileExists(const FileName: string): Boolean; 示例: ...
- DDD-领域驱动设计
识别领域事件 DDD战术篇:领域模型的应用 DDD战略篇:架构设计的响应力 DDD实战篇:分层架构的代码结构
- 【SQLAlchemy】SQLAlchemy技术文档(中文版)(中)
10.建立联系(外键) 是时候考虑怎样映射和查询一个和Users表关联的第二张表了.假设我们系统的用户可以存储任意数量的email地址.我们需要定义一个新表Address与User相关联. from ...
- SRM710 div1 MagicNim(博弈论)
题目大意: 给出n+1堆石子,前n堆石子的数量是a[i],最后一堆只有1个石子,但是具有魔力 拿走该石子的一方可以选择接下来是进行普通的Nim游戏还是anti-nim游戏 问是先手必胜还是必败 首先拿 ...
- 【题解】SHOI2008仙人掌图
本质上还是树形dp.建立圆方树,遇到圆点的时候直接求(和树形dp一样即可),遇到方点做中转点的时候要考虑会从圆的另一侧通过(需满足最短路径的原则).原本是对于圆上的点进行 \(n^{2}\) 的匹配, ...
- [bzoj] 2038 小Z的袜子(hose) || 莫队
原题 给出一个序列,求给定[l,r]内有任意取两个数,有多大概率是一样的 简单的莫队,每次+-当前区间里有的这个颜色的袜子的个数,最后除以(r-l+1)*(r-l)/2即可. 记得约分. #inclu ...
- java.lang.NoClassDefFoundError: Lorg/apache/log4j/Logger报错
java.lang.NoClassDefFoundError: Lorg/apache/log4j/Logger报错 错误提示: java.lang.NoClassDefFoundError: Lor ...
- oracle数据库导入导出方法
Oracle Database 10g以后引入了最新的数据泵(Data Dump)技术,使DBA或开发人员可以将数据库元数据(对象定义)和数据快速移动到另一个oracle数据库中. 数据泵导出导入(E ...
- Collection与Map的对比
Map:HashMap.HashTable 如何在它们之间选择 一.Array , Arrays Java所有“存储及随机访问一连串对象”的做法,array是最有效率的一种. 1. 效率高, ...