HDU1849 Rabbit and Grass()

用异或看取得的值是否为0判断

思想换没搞懂

#include<stdio.h>
int main()
{
    int ans,n,a;
    while(scanf("%d",&n),n){
        ans=0;
        while(n--){
            scanf("%d",&a);
            ans=ans^a;
        }
        if(ans==0) printf("Grass Win!\n");
        else printf("Rabbit Win!\n");
    }
    return 0;
}
时间: 2024-10-13 11:51:40

HDU1849 Rabbit and 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): 2145    Accepted Submission(s): 1622 Problem Description 大学时光是浪漫的,女生是浪漫的,圣诞更是浪漫的,但是Rabbit和Grass这两个大学女生在今年的圣诞节却表现得一点都不浪漫:不去逛商场,不去逛

HDU1849 Rabbit and Grass(NIM整理)

这类题就是有N堆东西,每次可以取任意堆的任意个 最后取完的获胜 就是把N堆读进来全部异或,不等0就赢了 /* *********************************************** Author :devil Created Time :2016/5/29 11:19:41 ************************************************ */ #include <cstdio> #include <cstring> #inc

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(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 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(杭电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 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这两个大学女生在今年的圣诞节却表现得一点都不浪漫:不去逛商场,不去

Rabbit and Grass(hdu-1849)

经典的博弈题,该题运用的原理叫尼姆博弈,可以运用位运算^来简单求解 . 将本题转换成从m堆牌中任意选择一堆,在里面拿任意个. 如果一旦有人遇到奇异局势,则此人必输,那么用ans^a;   如果最后ans==0那么最开始就是奇异局势,那么第一个人必输 #include<cstdio> #include<cstring> #include<iostream> #include<algorithm> #include<queue> #include&l

HDU 1849 Rabbit and Grass(nim博弈)

题目地址:HDU 1849 初次接触nim博弈,感觉好神奇的说...居然可以跟异或运算扯上关系....给人类的智商跪了...作为地球人我感到很自豪.. 具体证明什么的看这篇博客被.传送门 代码如下: #include <iostream> #include <cstdio> #include <string> #include <cstring> #include <stdlib.h> #include <math.h> #inclu