HDU 1850 Being a Good Boy in Spring Festival

题目地址:


http://acm.hdu.edu.cn/showproblem.php?pid=1850

经典的nim游戏,但需要求出下一步的方案数。

方法:对每一个堆,求出除此之外,其他堆的异或值(利用异或的结合性),如果该堆的石子的数目大于其他堆的异或值,那就有一种方案,否则没有。

#include <algorithm>
#include <bitset>
#include <deque>
#include <functional>
#include <fstream>
#include <list>
#include <iostream>
#include <iomanip>
#include <iterator>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <stack>
#include <sstream>
#include <utility>
#include <vector>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <climits>

#define up(i, lower, upper) for(int i = lower; i < upper; i++)
#define down(i, lower, upper) for(int i = upper-1; i >= lower; i--)

using namespace std;

#define MAX_N 10001
#define MAX_M 50001
typedef pair<int, int> pii;
typedef pair<double,int>pdi;
typedef pair<double, double> pdd;
typedef vector<int> vi;
typedef vector<pii> vpii;
typedef long long ll;
typedef unsigned long long ull;

const int INF = 0x7fffffff;
const int MAX = 110;
const double pi = acos(-1.0);
const double eps = 1.0e-9;

template<class T>

inline bool read(T &n){
	T x = 0, tmp = 1; char c = getchar();
	while ((c < '0' || c > '9') && c != '-' && c != EOF) c = getchar();
	if (c == EOF) return false;
	if (c == '-') c = getchar(), tmp = -1;
	while (c >= '0' && c <= '9') x *= 10, x += (c - '0'), c = getchar();
	n = x*tmp;
	return true;
}

template <class T>
inline void write(T n) {
	if (n < 0) {
		putchar('-');
		n = -n;
	}
	int len = 0, data[20];
	while (n) {
		data[len++] = n % 10;
		n /= 10;
	}
	if (!len) data[len++] = 0;
	while (len--) putchar(data[len] + 48);
}

int a[MAX];

int main(void)
{
    int n;
    while(read(n) && n)
    {
        for(int i = 0 ; i < n ; ++i)
            read(a[i]);
        int sum = a[0];
        for(int i = 1; i < n; ++i)
            sum ^= a[i];
        int total = 0;
        for(int i = 0 ; i < n ; ++i)
            if((sum ^ a[i] )< a[i] )
                total++;
        write(total);
        puts("");
    }
    return 0;
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值