2016ACM/ICPC亚洲区沈阳站 Solution
分类:
IT文章
•
2025-01-09 08:56:19
A - Thickest Burger
水。
1 #include <bits/stdc++.h>
2 using namespace std;
3
4 int t;
5 int a, b;
6
7 int main()
8 {
9 scanf("%d" ,&t);
10 while (t--)
11 {
12 scanf("%d%d", &a, &b);
13 if (a > b) swap(a, b);
14 printf("%d
", a + b * 2);
15 }
16 return 0;
17 }
View Code
B - Relative atomic mass
水。
1 #include <bits/stdc++.h>
2 using namespace std;
3
4 int t;
5 char s[100];
6
7 int main()
8 {
9 scanf("%d", &t);
10 while (t--)
11 {
12 scanf("%s", s);
13 int res = 0;
14 for (int i = 0, len = strlen(s); i < len; ++i)
15 {
16 if (s[i] == 'H') res += 1;
17 if (s[i] == 'C') res += 12;
18 if (s[i] == 'O') res += 16;
19 }
20 printf("%d
", res);
21 }
22 return 0;
23 }
View Code
$n^4 = (n - 1)^4 + 4 cdot (n - 1) ^ 3 + 6 cdot (n - 1) ^2 + 4 cdot (n - 1) ^ 2 + (n - 1) + 1$
1 #include <bits/stdc++.h>
2 using namespace std;
3
4 #define ll long long
5
6 const ll MOD = 2147493647;
7
8 int t;
9 ll n, a, b;
10
11 struct node
12 {
13 ll a[7][7];
14 node () { memset(a, 0, sizeof a); }
15 node operator * (const node &r) const
16 {
17 node ans = node();
18 for (int i = 0; i < 7; ++i) for (int j = 0; j < 7; ++j) for (int k = 0; k < 7; ++k)
19 ans.a[i][j] = (ans.a[i][j] + a[i][k] * r.a[k][j] % MOD) % MOD;
20 return ans;
21 }
22 };
23
24 ll tmp[7][7] =
25 {
26 1, 1, 0, 0, 0, 0, 0,
27 2, 0, 0, 0, 0, 0, 0,
28 1, 0, 1, 0, 0, 0, 0,
29 4, 0, 4, 1, 0, 0, 0,
30 6, 0, 6, 3, 1, 0, 0,
31 4, 0, 4, 3, 2, 1, 0,
32 1, 0, 1, 1, 1, 1, 1,
33 };
34
35 ll tmp2[7] =
36 {
37 0, 0, 16, 8, 4, 2, 1,
38 };
39
40 node qmod(ll n)
41 {
42 node base = node();
43 for (int i = 0; i < 7; ++i) for (int j = 0; j < 7; ++j)
44 base.a[i][j] = tmp[i][j];
45 node res = node();
46 for (int i = 0; i < 7; ++i) res.a[0][i] = tmp2[i];
47 while (n)
48 {
49 if (n & 1) res = res * base;
50 base = base * base;
51 n >>= 1;
52 }
53 return res;
54 }
55
56 int main()
57 {
58 scanf("%d", &t);
59 while (t--)
60 {
61 scanf("%lld%lld%lld", &n, &a, &b);
62 if (n == 1) printf("%lld
", a);
63 else if (n == 2) printf("%lld
", b);
64 else
65 {
66 tmp2[0] = b; tmp2[1] = a;
67 printf("%lld
", qmod(n - 2).a[0][0]);
68 }
69 }
70 return 0;
71 }