POJ 2975 Nim 尼姆博弈

题目大意:尼姆博弈,求先手必胜的情况数

题目思路:判断 ans=(a[1]^a[2]……^a[n]),求ans^a[i] < a[i]的个数。

#include<iostream>
#include<algorithm>
#include<cstring>
#include<vector>
#include<stdio.h>
#include<stdlib.h>
#include<queue>
#include<math.h>
#include<map>
#define INF 0x3f3f3f3f
#define MAX 1005
#define Temp 1000000000

using namespace std;

int a[MAX];

int main()
{
    int n,m,ans,cnt;
    while(scanf("%d",&n),n)
    {
        cnt=0;
        ans=0;
        memset(a,0,sizeof(a));
        for(int i=1;i<=n;i++)
        {
            scanf("%d",&a[i]);
            ans^=a[i];
        }
        for(int i=1;i<=n;i++)
        {
            if((ans^a[i])< a[i])
                cnt++;
        }
        printf("%d\n",cnt);
    }
    return 0;
}

时间: 2024-11-05 08:07:42

POJ 2975 Nim 尼姆博弈的相关文章

poj 2975 Nim 尼姆博弈,求取胜方案数

Nim Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 5002   Accepted: 2313 Description Nim is a 2-player game featuring several piles of stones. Players alternate turns, and on his/her turn, a player's move consists of removing one or mor

POJ2975 Nim 博弈论 尼姆博弈

http://poj.org/problem?id=2975 题目始终是ac的最大阻碍. 问只取一堆有多少方案可以使当前局面为先手必败. 显然由尼姆博弈的性质可以知道需要取石子使所有堆石子数异或和为0,那么将某一堆a个石子变为a^异或和即可. a1^a2^a3^...^an=y; a1^a2^a3^...^an^y=0; 1 #include<cstdio> 2 #include<cstring> 3 #include<algorithm> 4 #include<

POJ 3480 &amp; HDU 1907 John(尼姆博弈变形)

题目链接: PKU:http://poj.org/problem?id=3480 HDU:http://acm.hdu.edu.cn/showproblem.php?pid=1907 Description Little John is playing very funny game with his younger brother. There is one big box filled with M&Ms of different colors. At first John has to e

POJ 2234 Matches Game 尼姆博弈

题目大意:尼姆博弈,判断是否先手必胜. 题目思路: 尼姆博弈:有n堆各a[]个物品,两个人轮流从某一堆取任意多的物品,规定每次至少取一个,多者不限,最后取光者得胜. 获胜规则:ans=(a[1]^a[2] --^a[n]),若ans==0则后手必胜,否则先手必胜. #include<iostream> #include<algorithm> #include<cstring> #include<vector> #include<stdio.h>

[hdu-5795]A Simple Nim 博弈 尼姆博弈 SG函数打表找规律

[题目]题目链接 Two players take turns picking candies from n heaps,the player who picks the last one will win the game.On each turn they can pick any number of candies which come from the same heap(picking no candy is not allowed).To make the game more int

hdu 1850 Being a Good Boy in Spring Festival (尼姆博弈)

Being a Good Boy in Spring Festival Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 4658    Accepted Submission(s): 2781 Problem Description 一年在外 父母时刻牵挂春节回家 你能做几天好孩子吗寒假里尝试做做下面的事情吧 陪妈妈逛一次菜场悄悄给爸爸买

HDU 4315 Climbing the Hill (尼姆博弈)

Climbing the Hill Time Limit: 1000MS   Memory Limit: 32768KB   64bit IO Format: %I64d & %I64u Submit Status Description Alice and Bob are playing a game called "Climbing the Hill". The game board consists of cells arranged vertically, as the

HDUOJ--------A simple stone game(尼姆博弈扩展)(2008北京现场赛A题)

A simple stone game                                                                                                       Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)                                             

杭电 1536(尼姆博弈)

S-Nim <span size="+0"><strong><span style="font-family:Arial;font-size:12px;color:green;FONT-WEIGHT: bold">Time Limit: 5000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 4479