Menu

2014ACM-ICPC亚洲区西安站

Built with Qinghuai and Ari Factor

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
#include <bits/stdc++.h>
using namespace std;
int t, n, a, b;
int main(void)
{
	cin >> t;
	for (int ii = 1; ii <= t; ii++)
	{
		cin >> n;
		b = 0;
		for (int i = 1; i <= n; i++)
		{
			cin >> a;
			if (a % 3)
				b = 1;
		}
		printf("Case #%d: ", ii);
		if (b)
			printf("No\n");
		else
			printf("Yes\n");
	}
}

Color

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;

const int maxn = 1e6 + 10;
const LL mod = 1e9 + 7ll;
int T;
LL n, m, k;

LL jc[maxn], jcn[maxn];
inline LL mpow(LL a, LL b)
{
	LL ret = 1, tem = a;
	while (b)
	{
		if (b & 1)
			ret = ret * tem % mod;
		tem = tem * tem % mod;
		b >>= 1;
	}
	return ret;
}
inline LL c(LL a, LL b)
{
	return jc[a] * jcn[b] % mod * jcn[a - b] % mod;
}
void init()
{
	jc[1] = jc[0] = 1;
	jcn[1] = jcn[0] = 1;
	for (int i = 2; i <= 1000000; i++)
		jc[i] = jc[i - 1] * i % mod, jcn[i] = mpow(jc[i], mod - 2);
}

LL Pow(LL a, LL k)
{
	if (k == 0)
		return 1ll;
	LL now = Pow(a, k / 2);
	now = now * now % mod;
	if (k % 2 == 1)
		now = now * a % mod;
	return now;
}

LL made(LL p, LL q)
{
	LL now = p * Pow(p - 1, n - 1) % mod * c(k, q) % mod;
	return now;
}

LL cc(LL m, LL k)
{
	LL now = 1ll;
	for (LL i = m; i >= m - k + 1; i--)
		now = now * i % mod;
	now = now * jcn[k] % mod;
	return now;
}

int main()
{
	scanf("%d", &T);
	init();
	for (int t = 1; t <= T; t++)
	{
		scanf("%lld%lld%lld", &n, &m, &k);

		LL d = 1ll, s = 0, ans = 0;
		for (LL i = k; i >= 1; i--)
		{
			LL now = made(i, s);
			ans = (ans + d * now % mod + mod) % mod;
			d = d * (-1ll);
			s++;
		}
		ans = ans * cc(m, k) % mod;
		printf("Case #%d: %lld\n", t, ans);
	}

	return 0;
}

Last Defence

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
#include <bits/stdc++.h>
#define ll long long
using namespace std;
ll a, b, c, t, ans;

ll deal(ll a, ll b)
{
	if (a == 0 && b == 0)
		return 1;
	if (b == 0)
		return 2;
	if (a % b == 0)
		return a / b + 1;
	ll c = a % b;
	return a / b + deal(max(b, c), min(b, c));
}

int main(void)
{
	cin >> t;
	for (int ii = 1; ii <= t; ii++)
	{
		cin >> a >> b;
		ans = deal(max(a, b), min(a, b));
		printf("Case #%d: %lld\n", ii, ans);
	}
}