ZOJ 3591 & 3594

3591 Nim

这题连基本的Nim都不告诉怎么,让比赛时没见过的情何以堪。

#include <cstdio>
#include <algorithm>
using namespace std;
typedef long long ll;

int T, N, S, W;
int a[1000001];

inline void Generate()
{
	int g = S;
	++ N;
	for(int i=1; i<N; ++i)
	{ 
		a[i] = g;
		if( a[i] == 0 ) a[i] = g = W;
		a[i] ^= a[i-1];
		if( g%2 == 0 )  g = g / 2;
		else	g = (g / 2) ^ W;
	}
}

int main()
{
	scanf("%d", &T);
	while(T --)
	{
		scanf("%d%d%d", &N, &S, &W);
		ll sum = N*(N+1ll)/2;
		Generate();
		sort(a+1, a+N);
		S = 1;
		for(int i=2; i<N; ++i)
		{
			if(a[i] == a[i-1]) ++S;
			else
			{
				if(a[i-1]==0) sum -= S;
				sum -= S*(S-1ll)/2;
				S = 1;
			}
		}
		sum -= S*(S-1ll)/2;
		printf("%lld\n", sum);
	}
	return 0;
}

3594 Sexagenary Cycle

公元不是从零年开始的,莫不是因为那时没有计算机。

#include <iostream>
#include <string>
using namespace std;

const string h[10] = {
	 "Jia", "Yi", "Bing", "Ding", "Wu", 
	 "Ji", "Geng", "Xin", "Ren", "Gui"};
const string e[12] = {
	"zi", "chou", "yin", "mao", "chen", "si",
	"wu", "wei", "shen", "you", "xu", "hai"};

int main()
{
	int T, year;
	cin >> T;
	while(T --)
	{
		cin >> year;
		if(year < 0)
			year += 1;
		if(year >= 1911)
		{
			cout << h[(year-1911+7)%10];
			cout << e[(year-1911+11)%12];
			cout << endl;
		}
		else
		{
			year = 1911 - year;
			cout << h[(17-year%10)%10];
			cout << e[(23-year%12)%12];
			cout << endl;
		}
	}
	return 0;
}

3695 Two Sequences

原来只差一次求导,启蒙时没学过级数确实不够敏锐啊。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值