HDU 1849 Rabbit and Grass(nim博弈)

题目地址:HDU 1849

初次接触nim博弈,感觉好神奇的说。。。居然可以跟异或运算扯上关系。。。。给人类的智商跪了。。。作为地球人我感到很自豪。。

具体证明什么的看这篇博客被。传送门

代码如下:

#include <iostream>
#include <cstdio>
#include <string>
#include <cstring>
#include <stdlib.h>
#include <math.h>
#include <ctype.h>
#include <queue>
#include <map>
#include <set>
#include <algorithm>

using namespace std;
int main()
{
    int n, x, sum, i;
    while(scanf("%d",&n)!=EOF&&n)
    {
        sum=0;
        for(i=0;i<n;i++)
        {
            scanf("%d",&x);
            sum^=x;
        }
        if(sum)
            puts("Rabbit Win!");
        else
            puts("Grass Win!");
    }
    return 0;
}
时间: 2024-12-23 20:25:31

HDU 1849 Rabbit and Grass(nim博弈)的相关文章

HDU - 1849 - Rabbit and Grass

先上题目: Rabbit and Grass Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 2097    Accepted Submission(s): 1579 Problem Description 大学时光是浪漫的,女生是浪漫的,圣诞更是浪漫的,但是Rabbit和Grass这两个大学女生在今年的圣诞节却表现得一点都不浪漫:不去逛

hdu 1849 Rabbit and Grass 谁都喜欢刷水题。。尼姆博弈

Rabbit and Grass Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 2507    Accepted Submission(s): 1888 Problem Description 大学时光是浪漫的,女生是浪漫的,圣诞更是浪漫的,但是Rabbit和Grass这两个大学女生在今年的圣诞节却表现得一点都不浪漫:不去逛商场,不去

hdu 1849 Rabbit and Grass(nim)

Rabbit and Grass Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 4024    Accepted Submission(s): 3040 Problem Description 大学时光是浪漫的,女生是浪漫的,圣诞更是浪漫的,但是Rabbit和Grass这两个大学女生在今年的圣诞节却表现得一点都不浪漫:不去逛商场,不去逛

HDU Rabbit and Grass 兔子和草 (Nim博弈,水)

思路:简单Nim博弈,只需要将所给的数字全部进行异或,结果为0,则先手必败.否则必胜.知道方法的人1分钟写完代码,不知道的人研究几小时都难写. 1 #include <iostream> 2 using namespace std; 3 int main() 4 { 5 //freopen("input.txt", "r", stdin); 6 int t, n, m; 7 while(cin>>t,t) 8 { 9 int ans,tmp;

hdu 1849(Rabbit and Grass) 尼姆博弈

Rabbit and Grass Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 3864    Accepted Submission(s): 2919 Problem Description 大学时光是浪漫的,女生是浪漫的,圣诞更是浪漫的,但是Rabbit和Grass这两个大学女生在今年的圣诞节却表现得一点都不浪漫:不去逛商场,不去逛

Rabbit and Grass HDU - 1849 (Bash+Nim)

就是Bash 和 Nim 博弈的结合  可以直接 res ^= (Li + 1) % Mi 也可以 sg打个表  我打了个表 #include <iostream> #include <cstdio> #include <sstream> #include <cstring> #include <map> #include <set> #include <vector> #include <stack> #in

Rabbit and Grass(杭电1849)(尼姆博弈)

Rabbit and Grass Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 2254    Accepted Submission(s): 1704 Problem Description 大学时光是浪漫的,女生是浪漫的,圣诞更是浪漫的,但是Rabbit和Grass这两个大学女生在今年的圣诞节却表现得一点都不浪漫:不去逛商场,不去

hdu 1849 (尼姆博弈)

http://acm.hdu.edu.cn/showproblem.php?pid=1849 简单的尼姆博弈: 代码如下: #include <iostream> #include <cstdio> using namespace std; int main() { int m,n,t; while(cin>>m,m) { int ans=0; for(int i=0; i<m; i++) { cin>>n; ans^=n; } if(ans==0)

[Nim博弈]hdu 1850 Being a Good Boy in Spring Festival

题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=1850 Being a Good Boy in Spring Festival Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 4053    Accepted Submission(s): 2394 Problem Description