您的位置:首页 > 其它

ZOJ 3591 & 3594

2013-04-07 21:12 323 查看
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

原来只差一次求导,启蒙时没学过级数确实不够敏锐啊。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: