Hdu 4768 Flyer(2013长春网络赛)

不断的异或就可以了, 用了一个等差数列连续异或的模板


#include <cstdio>

typedef __int64 LL;
#include <iostream>
using namespace std;

LL Get(LL a,LL b,LL c,LL n) {
	LL res=0;
	res+=(b/c)*n;b%=c;
	res+=(a/c)*n*(n-1)/2;a%=c;
	if (a*n+b<c) return res;
	else return res+Get(c,(a*n+b)%c,a,(a*n+b)/c);
}
LL GetYiHuo(LL x, LL y, LL z)  //以x开始, y为结束, z为等差 连续异或
{
	{
		LL k,ans,Sum,P,i;
		ans=0;
		k=(y-x)/z+1;P=1;
		for (i=1;i<=35;i++,P<<=1) {
			Sum=Get(z,x,P,k);
			if (Sum & 1) ans+=P;
		}
		return ans;
	}
}

LL a[20003], b[20003], c[20003];


int main()
{
	int N;
	while(scanf("%d", &N) != EOF)
	{
		LL x, y, z;
		LL tmp = 0;
		for(int i = 0; i < N; i++)
		{
			scanf("%I64d %I64d %I64d", &x, &y, &z);
			a[i] = x, b[i] = y, c[i] = z;
			LL tt = GetYiHuo(x, y, z);
			tmp ^= tt;
		}
		if(tmp == 0)
		{
			puts("DC Qiang is unhappy.");
			continue;
		}
		int count = 0;
		for(int i = 0; i < N; i++)
		{
			if(tmp >= a[i] && (tmp - a[i]) % c[i] == 0 && tmp <= b[i])
				count++;
		}
		printf("%I64d %I64d\n", tmp, count);
	}
	return 0;
}


这短代码很坑的, 用c++ 可以过, 但是改成g++就wa了

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值