A. Stones
Description
给出3堆物品,个数分别为a,b,c
有两种取数方式,a1b2,b1c2,问最多取多少物品
Solution
$O(n^2)暴力$

1 #include <algorithm>
2 #include <cctype>
3 #include <cmath>
4 #include <cstdio>
5 #include <cstdlib>
6 #include <cstring>
7 #include <iostream>
8 #include <map>
9 #include <queue>
10 #include <set>
11 #include <stack>
12 #if __cplusplus >= 201103L
13 #include <unordered_map>
14 #include <unordered_set>
15 #endif
16 #include <vector>
17 #define lson rt << 1, l, mid
18 #define rson rt << 1 | 1, mid + 1, r
19 #define LONG_LONG_MAX 9223372036854775807LL
20 #define ll LL
21 using namespace std;
22 typedef long long ll;
23 typedef long double ld;
24 typedef unsigned long long ull;
25 typedef pair<int, int> P;
26 int n, m, k;
27 const int maxn = 1e5 + 10;
28 template <class T>
29 inline T read()
30 {
31 int f = 1;
32 T ret = 0;
33 char ch = getchar();
34 while (!isdigit(ch))
35 {
36 if (ch == '-')
37 f = -1;
38 ch = getchar();
39 }
40 while (isdigit(ch))
41 {
42 ret = (ret << 1) + (ret << 3) + ch - '0';
43 ch = getchar();
44 }
45 ret *= f;
46 return ret;
47 }
48 template <class T>
49 inline void write(T n)
50 {
51 if (n < 0)
52 {
53 putchar('-');
54 n = -n;
55 }
56 if (n >= 10)
57 {
58 write(n / 10);
59 }
60 putchar(n % 10 + '0');
61 }
62 template <class T>
63 inline void writeln(const T &n)
64 {
65 write(n);
66 puts("");
67 }
68 int main(int argc, char const *argv[])
69 {
70 #ifndef ONLINE_JUDGE
71 freopen("in.txt", "r", stdin);
72 freopen("out.txt", "w", stdout);
73 #endif
74 int t = read<int>();
75 while (t--)
76 {
77 int a = read<int>(), b = read<int>(), c = read<int>();
78 int res = 0;
79 for (int t1 = 0; t1 <= 100; t1++)
80 for (int t2 = 0; t2 <= 100; t2++)
81 if (t1 <= a && 2 * t1 + t2 <= b && 2 * t2 <= c)
82 res = max(res, 3 * (t1 + t2));
83 writeln(res);
84 }
85 return 0;
86 }
B. Alice and the List of Presents
Description
给出n种无穷多的球,m个有差别的盒子,要求每种球至少取一个放在某个盒子里的方案数。

Solution
人肉打表找规律

$res={(2^m-1)}^n$
快速幂取模

1 #include <algorithm>
2 #include <cctype>
3 #include <cmath>
4 #include <cstdio>
5 #include <cstdlib>
6 #include <cstring>
7 #include <iostream>
8 #include <map>
9 #include <queue>
10 #include <set>
11 #include <stack>
12 #if __cplusplus >= 201103L
13 #include <unordered_map>
14 #include <unordered_set>
15 #endif
16 #include <vector>
17 #define lson rt << 1, l, mid
18 #define rson rt << 1 | 1, mid + 1, r
19 #define LONG_LONG_MAX 9223372036854775807LL
20 #define ll LL
21 using namespace std;
22 typedef long long ll;
23 typedef long double ld;
24 typedef unsigned long long ull;
25 typedef pair<int, int> P;
26 int n, m, k;
27 const int maxn = 1e5 + 10;
28 const int mod = 1e9 + 7;
29 template <class T>
30 inline T read()
31 {
32 int f = 1;
33 T ret = 0;
34 char ch = getchar();
35 while (!isdigit(ch))
36 {
37 if (ch == '-')
38 f = -1;
39 ch = getchar();
40 }
41 while (isdigit(ch))
42 {
43 ret = (ret << 1) + (ret << 3) + ch - '0';
44 ch = getchar();
45 }
46 ret *= f;
47 return ret;
48 }
49 template <class T>
50 inline void write(T n)
51 {
52 if (n < 0)
53 {
54 putchar('-');
55 n = -n;
56 }
57 if (n >= 10)
58 {
59 write(n / 10);
60 }
61 putchar(n % 10 + '0');
62 }
63 template <class T>
64 inline void writeln(const T &n)
65 {
66 write(n);
67 puts("");
68 }
69 ll qpow(ll a, int b)
70 {
71 ll res = 1;
72 while (b)
73 {
74 if (b & 1)
75 res = res * a % mod;
76 a = a * a % mod;
77 b >>= 1;
78 }
79 return res;
80 }
81 int main(int argc, char const *argv[])
82 {
83 #ifndef ONLINE_JUDGE
84 freopen("in.txt", "r", stdin);
85 freopen("out.txt", "w", stdout);
86 #endif
87 n = read<int>(), m = read<int>();
88 writeln(qpow(qpow(2, m) - 1, n));
89 return 0;
90 }
C. Labs
Description

Solution
将$n^2$个元素按大小分为n组,大小大小...组合
不知道咋证明

1 #include <algorithm>
2 #include <cctype>
3 #include <cmath>
4 #include <cstdio>
5 #include <cstdlib>
6 #include <cstring>
7 #include <iostream>
8 #include <map>
9 #include <queue>
10 #include <set>
11 #include <stack>
12 #if __cplusplus >= 201103L
13 #include <unordered_map>
14 #include <unordered_set>
15 #endif
16 #include <vector>
17 #define lson rt << 1, l, mid
18 #define rson rt << 1 | 1, mid + 1, r
19 #define LONG_LONG_MAX 9223372036854775807LL
20 #define ll LL
21 using namespace std;
22 typedef long long ll;
23 typedef long double ld;
24 typedef unsigned long long ull;
25 typedef pair<int, int> P;
26 int n, m, k;
27 const int maxn = 1e5 + 10;
28 template <class T>
29 inline T read()
30 {
31 int f = 1;
32 T ret = 0;
33 char ch = getchar();
34 while (!isdigit(ch))
35 {
36 if (ch == '-')
37 f = -1;
38 ch = getchar();
39 }
40 while (isdigit(ch))
41 {
42 ret = (ret << 1) + (ret << 3) + ch - '0';
43 ch = getchar();
44 }
45 ret *= f;
46 return ret;
47 }
48 template <class T>
49 inline void write(T n)
50 {
51 if (n < 0)
52 {
53 putchar('-');
54 n = -n;
55 }
56 if (n >= 10)
57 {
58 write(n / 10);
59 }
60 putchar(n % 10 + '0');
61 }
62 template <class T>
63 inline void writeln(const T &n)
64 {
65 write(n);
66 puts("");
67 }
68 int a[maxn];
69 set<int> s[305];
70 int main(int argc, char const *argv[])
71 {
72 #ifndef ONLINE_JUDGE
73 freopen("in.txt", "r", stdin);
74 freopen("out.txt", "w", stdout);
75 #endif
76 n = read<int>();
77 for (int i = 1; i <= n; i++)
78 for (int j = 1; j <= n; j++)
79 s[i].emplace((i - 1) * n + j);
80 for (int i = 1; i <= n; i++)
81 {
82 for (int j = 1; j <= n; j++)
83 {
84 if (!(j & 1))
85 {
86 write(*s[j].begin());
87 putchar(' ');
88 s[j].erase(s[j].begin());
89 }
90 else
91 {
92 write(*s[j].rbegin());
93 putchar(' ');
94 s[j].erase(*s[j].rbegin());
95 }
96 }
97 puts("");
98 }
99 return 0;
100 }
D. Alice and the Doll
Description

Solution
赛后补题,模拟题意。
每次直走到不能走为止,然后右转继续,蛇形走位。
记录四个边界,最上一行,最下一行,最左一列,最右一列。每次更新坐标需要在边界以内。
注意开始可以直接右转往下走。

1 /*
2 蛇形走位
3 */
4 #include <algorithm>
5 #include <cctype>
6 #include <cmath>
7 #include <cstdio>
8 #include <cstdlib>
9 #include <cstring>
10 #include <iostream>
11 #include <map>
12 #include <queue>
13 #include <set>
14 #include <stack>
15 #if __cplusplus >= 201103L
16 #include <unordered_map>
17 #include <unordered_set>
18 #endif
19 #include <vector>
20 #define lson rt << 1, l, mid
21 #define rson rt << 1 | 1, mid + 1, r
22 #define LONG_LONG_MAX 9223372036854775807LL
23 #define ll LL
24 using namespace std;
25 typedef long long ll;
26 typedef long double ld;
27 typedef unsigned long long ull;
28 typedef pair<int, int> P;
29 int n, m, k;
30 const int maxn = 1e5 + 10;
31 template <class T>
32 inline T read()
33 {
34 int f = 1;
35 T ret = 0;
36 char ch = getchar();
37 while (!isdigit(ch))
38 {
39 if (ch == '-')
40 f = -1;
41 ch = getchar();
42 }
43 while (isdigit(ch))
44 {
45 ret = (ret << 1) + (ret << 3) + ch - '0';
46 ch = getchar();
47 }
48 ret *= f;
49 return ret;
50 }
51 template <class T>
52 inline void write(T n)
53 {
54 if (n < 0)
55 {
56 putchar('-');
57 n = -n;
58 }
59 if (n >= 10)
60 {
61 write(n / 10);
62 }
63 putchar(n % 10 + '0');
64 }
65 template <class T>
66 inline void writeln(const T &n)
67 {
68 write(n);
69 puts("");
70 }
71 set<int> xi[maxn], yi[maxn], xd[maxn], yd[maxn];
72 int x, y;
73 int l, r, u, d, dic;
74 void init()
75 {
76 x = y = 1;
77 dic = 0;
78 l = u = 0;
79 r = m + 1, d = n + 1;
80 }
81 ll solve()
82 {
83 ll cnt = 1;
84 while (1)
85 {
86 if (dic == 0)
87 {
88 int cur = *xi[x].upper_bound(y);
89 cur = min(cur, r);
90 if (cur - y == 1)
91 return cnt;
92 cnt += cur - y - 1;
93 y = cur - 1;
94 u = max(x, u); //右是由上转移而来,更新上边界
95 }
96 else if (dic == 1)
97 {
98 int cur = *yi[y].upper_bound(x);
99 cur = min(cur, d);
100 if (cur - x == 1)
101 return cnt;
102 cnt += cur - x - 1;
103 x = cur - 1;
104 r = min(r, y); //下是由右转移而来,更新右边界
105 }
106 else if (dic == 2)
107 {
108 int cur = -*xd[x].upper_bound(-y);
109 cur = max(cur, l);
110 if (y - cur == 1)
111 return cnt;
112 cnt += y - cur - 1;
113 y = cur + 1;
114 d = min(d, x);
115 }
116 else if (dic == 3)
117 {
118 int cur = -*yd[y].upper_bound(-x);
119 cur = max(cur, u);
120 if (x - cur == 1)
121 return cnt;
122 cnt += x - cur - 1;
123 x = cur + 1;
124 l = max(l, y);
125 }
126 dic++;
127 if (dic == 4)
128 dic = 0;
129 }
130 return cnt;
131 }
132 int main(int argc, char const *argv[])
133 {
134 #ifndef ONLINE_JUDGE
135 freopen("in.txt", "r", stdin);
136 // freopen("out.txt", "w", stdout);
137 #endif
138 n = read<int>(), m = read<int>();
139 k = read<int>();
140 for (int i = 1; i <= n; i++)
141 xi[i].emplace(0), xi[i].emplace(m + 1), xd[i].emplace(0), xd[i].emplace(-m - 1);
142 for (int i = 1; i <= m; i++)
143 yi[i].emplace(0), yi[i].emplace(n + 1), yi[i].emplace(0), yi[i].emplace(-n - 1);
144 for (int i = 0; i < k; i++)
145 {
146 int a = read<int>(), b = read<int>();
147 xi[a].emplace(b);
148 yi[b].emplace(a);
149 xd[a].emplace(-b);
150 yd[b].emplace(-a);
151 }
152 init();
153 ll cur = solve();
154 if (cur == 1LL * n * m - k)
155 puts("Yes");
156 else
157 {
158 init();
159 dic = 1;
160 cur = solve();
161 if (cur == 1LL * n * m - k)
162 puts("Yes");
163 else
164 puts("No");
165 }
166 return 0;
167 }
