ACM 第八届山东省赛 A题 Return of the Nim


可再提交链接:

http://www.sdutacm.org/onlinejudge2/index.php/Home/Index/problemdetail/pid/3893.html

Return of the Nim

Time Limit: 1000MS  Memory Limit: 65536KB
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:
    1. Choose one pile and remove k(k >0) stones from it;
    2. Remove k stones from all piles, where 1≤kthe 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≤in−1
Output

For each game, print the name of the winner on a new line (i.e., either "Sherlock" or "Watson")

Example Input
2
3
2 3 2
2
2 1
Example Output
Sherlock
Watson
Hint
Author
“浪潮杯”山东省第八届ACM大学生程序设计竞赛(感谢青岛科技大学)


两个取法:

1 是从中任意一堆中取k个;

2 是从全部堆中 每一堆取k个;

两种方法 对应两种博弈  一个是尼姆博奕 另一个是威佐夫博弈;

尼姆博奕: 三堆各若干个物品,两个人轮流从某一堆取任意多的物品,规定每次至少取一个,不封顶,最后取光者得胜。

威佐夫博弈:有两堆各若干个物品,两个人轮流从某一堆或同时从两堆中取同样多的物品,规定每次至少取一个,不封顶,最后取光者得胜。


套模板即可

#include <iostream>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <stdio.h>
#include <string>

using namespace std;

int main()
{
    int T,i;
    cin>>T;
    int a[10000];

    while(T--)
    {
        int n;
        cin>>n;
        int sum=0;
        memset(a,0,sizeof(a));
        for(i=0;i<n;i++)
        {
            cin>>a[i];
            sum^=a[i];
        }
        if(n==2)
        {
            int k=fabs(a[1]-a[0]);
            int ans=(int)((k*(sqrt(5)+1)/2));
            if(ans==min(a[1],a[0]))
                printf("Watson\n");
            else
                printf("Sherlock\n");
        }
        else
        {
            if(sum)
                printf("Sherlock\n");
            else
                printf("Watson\n");
        }
    }
    return 0;
}



评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值