HDU-1851-A Simple Game

Posted 1013star

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了HDU-1851-A Simple Game相关的知识,希望对你有一定的参考价值。

A Simple Game

Agrael likes play a simple game with his friend Animal during the classes. In this Game there are n piles of stones numbered from 1 to n, the 1st pile has M 1 stones, the 2nd pile has M 2 stones, ... and the n-th pile contain M n stones. Agrael and Animal take turns to move and in each move each of the players can take at most L 1stones from the 1st pile or take at most L 2 stones from the 2nd pile or ... or take L n stones from the n-th pile. The player who takes the last stone wins. 

After Agrael and Animal have played the game for months, the teacher finally got angry and decided to punish them. But when he knows the rule of the game, he is so interested in this game that he asks Agrael to play the game with him and if Agrael wins, he won‘t be punished, can Agrael win the game if the teacher and Agrael both take the best move in their turn? 

The teacher always moves first(-_-), and in each turn a player must takes at least 1 stones and they can‘t take stones from more than one piles. 
InputThe first line contains the number of test cases. Each test cases begin with the number n (n ≤ 10), represent there are n piles. Then there are n lines follows, the i-th line contains two numbers M i and L i (20 ≥ M i > 0, 20 ≥ L i > 0). 
OutputYour program output one line per case, if Agrael can win the game print "Yes", else print "No". 
Sample Input
2
1
5 4
2
1 1
2 2
Sample Output
Yes
No
题意:

n堆石子,分别有M1,M2,...Mn个石子,每个堆最多取L1,L2...Ln个石头,两个人分别取石子,每次只能在一堆里取,取完最后一个石子的人获胜。   若后手赢(学生),输出Yes。

题解:

sg打表找规律~这个题一看就是NIM和巴什博弈结合。瞎猜一波竟然对了(手动滑稽~~)
 
 1 #include<iostream>
 2 #include<cstdio>
 3 #include<cstring>
 4 #include<algorithm>
 5 using namespace std;
 6 int casen;
 7 int m,l;
 8 int sg[1100];
 9 int dfs(int t)
10 {
11     int vis[1100];
12     if(sg[t]!=-1)
13         return sg[t];
14     memset(vis,0,sizeof(vis));
15     for(int i=1;i<=l;i++)
16     {
17         if(t>=i)
18             vis[dfs(t-i)]=1;
19     }
20     for(int i=0;i<110;i++)
21     {
22         //printf("%d",vis[i]);
23         if(vis[i]==0)
24         {
25             return sg[t]=i;
26             break;
27         } 
28     }
29 }
30 int main()
31 {
32     scanf("%d",&casen);
33     while(casen--)
34     {
35         int n;
36         int ans=0;
37         
38         scanf("%d",&n);
39         for(int i=1;i<=n;i++)
40         {
41                         memset(sg,-1,sizeof(sg));
42             scanf("%d%d",&m,&l);
43             sg[0]=0;
44             dfs(m);
45         //    cout<<sg[m]<<endl;
46             ans^=sg[m]; 
47         }
48         if(ans==0)
49             puts("Yes");
50         else
51             puts("No");
52     }
53 }                                    

瞎猜版:

#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;

int m,l;
int casen;
int n;
int main()
{
    int casen;
    cin>>casen;
    while(casen--)
    {
        scanf("%d",&n);
        int ans=0;
        while(n--)
        {
            scanf("%d%d",&m,&l);
                ans^=(m%(l+1));
        }
        if(!ans)
            puts("Yes");
        else
            puts("No");
    }
}

 

 
 







以上是关于HDU-1851-A Simple Game的主要内容,如果未能解决你的问题,请参考以下文章

编译原理构建一个简单的解释器(Let’s Build A Simple Interpreter. Part 7.)(笔记)解释器 interpreter 解析器 parser 抽象语法树AST(代码片

Codeforces Round #316 (Div. 2) B. Simple Game

[Coding Made Simple] Optimal Strategy Game Pick from Ends of array

2017中国大学生程序设计竞赛-哈尔滨站 H - A Simple Stone Game

A Simple Stone Game-找素因子(欧拉函数)-2017中国大学生程序设计竞赛-哈尔滨站-重现赛

简单Elixir游戏服设计-玩法simple_poker