poj 2975 Nim

Nim博弈题:这个题是要你求如果先手能赢,有几种策略;

View Code
#include<iostream>

 #include<cstdio>

 #include<cstdlib>

 #include<algorithm>

 #include<cmath>

 #include<queue>

 #include<set>

 #include<map>

 #include<cstring>

 #include<vector>

 #include<string>

 #define LL long long

 using namespace std;

 

 int main(  )

 {

    int n,num[1024];

    while( scanf( "%d",&n ),n )

    {

        int s = 0;

        for( int i = 0 ; i < n ;i ++ )

        {

              scanf( "%d",&num[i] );

              s ^= num[i];    

         }

         int ans = 0;

         if( s != 0 )

         for( int i = 0 ; i < n ; i ++ )

         {

             if( num[i] > (s^num[i])  ) ans++;

         }        

         printf( "%d\n",ans );

    }

     //system( "pause" );

     return 0;

 }

 

你可能感兴趣的:(poj)