img
2024 ICPC ShaanXi Provincial
Contest
A
A是一个简单模拟题。
只需要观察到可以用二进制就杀了。
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
|
#include <bits/stdc++.h> using namespace std; using ll = long long; char ans[] = {'x', 'w', 'r'}; void Totoro() { string s; cin >> s; for (auto c : s) { int x = int(c - '0'); for (int i = 2; i >= 0; i--) { if (x >> i & 1) { cout << ans[i]; } else { cout << '-'; } } } cout << '\n'; } int main() { int t; cin >> t; while (t--) { Totoro(); } return 0; }
|
B
B是一个恶心的构造。
考虑情况:
行列都是偶数:
1 2 3 4 5 6 7
| 以 6 × 8 为例 11111111 1*1*1*11 11*1*1*1 1*1*1*11 11*1*1*1 11111111
|
构造出每一行每一列恰好都有一个11即可。
如果列是奇数,行是偶数,或者行是奇数,列是偶数,都可以转化为行是偶数,列是奇数求解:
观察可以发现按照偶数*偶数
去构造有两个11会*
在一起,改成加号。
如果都是奇数,就需要斜着构造了,可以打表观察。
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 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267
|
#include <bits/stdc++.h> using namespace std; using ll = long long; const int N = 1e3 + 100; char a[N][N]; void Totoro() { int n; cin >> n; int m; cin >> m; if (n % 2 == 0 && m % 2 == 0) { for (int i = 1; i <= n; i++) { a[i][1] = a[i][m] = '1'; } for (int i = 1; i <= m; i++) { a[1][i] = a[n][i] = '1'; } for (int i = 2; i <= n - 1; i++) { if (i % 2 == 0) { for (int j = 2; j <= m - 1; j++) { if (j % 2 == 0) { a[i][j] = '*'; } else { a[i][j] = '1'; } } } else { for (int j = 2; j <= m - 1; j++) { if (j % 2 == 1) { a[i][j] = '*'; } else { a[i][j] = '1'; } } } } for (int i = 1; i <= n; i++) { for (int j = 1; j <= m; j++) { cout << a[i][j]; } cout << '\n'; } } else { if (n % 2 == 1 && m % 2 == 0) { swap(n, m); for (int i = 1; i <= n; i++) { a[i][1] = a[i][m] = '1'; } for (int i = 1; i <= m; i++) { a[1][i] = a[n][i] = '1'; } for (int i = 2; i <= n - 1; i++) { if (i % 2 == 0) { for (int j = 2; j <= m - 1; j++) { if (j % 2 == 0) { a[i][j] = '*'; } else { a[i][j] = '1'; } } } else { for (int j = 2; j <= m - 1; j++) { if (j % 2 == 1) { a[i][j] = '*'; } else { a[i][j] = '1'; } } } } if (m > 3) { for (int i = 3; i < n; i += 2) { a[i][3] = '+'; } } for (int i = 1; i <= m; i++) { for (int j = 1; j <= n; j++) { cout << a[j][i]; } cout << '\n'; } } else if (n % 2 == 0 && m % 2 == 1) { for (int i = 1; i <= n; i++) { a[i][1] = a[i][m] = '1'; } for (int i = 1; i <= m; i++) { a[1][i] = a[n][i] = '1'; } for (int i = 2; i <= n - 1; i++) { if (i % 2 == 0) { for (int j = 2; j <= m - 1; j++) { if (j % 2 == 0) { a[i][j] = '*'; } else { a[i][j] = '1'; } } } else { for (int j = 2; j <= m - 1; j++) { if (j % 2 == 1) { a[i][j] = '*'; } else { a[i][j] = '1'; } } } } if (m > 3) { for (int i = 3; i < n; i += 2) { a[i][3] = '+'; } } for (int i = 1; i <= n; i++) { for (int j = 1; j <= m; j++) { cout << a[i][j]; } cout << '\n'; } } else { for (int i = 1; i <= n; i++) { a[i][1] = a[i][m] = '1'; } for (int i = 1; i <= m; i++) { a[1][i] = a[n][i] = '1'; } for (int i = 2; i <= n - 1; i++) { if (i % 2 == 0) { for (int j = 2; j <= m - 1; j++) { if (j % 2 == 0) { a[i][j] = '*'; } else { a[i][j] = '1'; } } } else { for (int j = 2; j <= m - 1; j++) { if (j % 2 == 1) { a[i][j] = '*'; } else { a[i][j] = '1'; } } } } for (int i = 3, j = 3; i < max(n, m); i += 2) { if (i < n && i < m) a[i][i] = '+'; else if (i < n) { if (i < n && j < m) { a[i][j] = '+'; j += 2; if (j >= m) j = 3; } } else { if (j < n && i < m) { a[j][i] = '+'; j += 2; if (j >= n) j = 3; } } } for (int i = 1; i <= n; i++) { for (int j = 1; j <= m; j++) { cout << a[i][j]; } cout << '\n'; } } } } int main() { int t = 1; while (t--) { Totoro(); } return 0; }
|
C
直接i->a[i]
连边,得到基环内向森林,若有环,贡献加上环的大小,不然就是一个最长路。直接用拓扑排序:
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
|
#include <bits/stdc++.h> using namespace std; using ll = long long; const int N = 1e6 + 100; int deg[N]; int f[N]; int a[N]; void Totoro() { int n; cin >> n; for (int i = 1; i <= n; i++) { cin >> a[i]; ++deg[a[i]]; } queue<int> q; int ans = 2 * n; for (int i = 1; i <= 2 * n; i++) { if (!deg[i]) { q.push(i); } } while (!q.empty()) { int now = q.front(); q.pop(); --ans; if (now > n) { ans += f[now]; continue; } f[a[now]] = max(f[a[now]], f[now] + 1); if (--deg[a[now]] == 0) { q.push(a[now]); } } cout << ans << '\n'; } int main() { int t = 1; while (t--) { Totoro(); } return 0; }
|
F
数字可以相同,因此直接输出最大值。
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
|
#include <bits/stdc++.h> using namespace std; using ll = long long; const int N = 1e6 + 100; void Totoro() { int n; cin >> n; int maxn = 0; vector<int> a(n + 1); for (int i = 1; i <= n; i++) { cin >> a[i]; maxn = max(a[i], maxn); } cout << maxn << '\n'; } int main() { int t; cin >> t; while (t--) { Totoro(); } return 0; }
|
G
核心:九进制求解。
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
|
#include <bits/stdc++.h> using namespace std; using ll = long long; const int N = 12; int a[N]; void Totoro() { ll n, x; cin >> n >> x; int cnt = 0; for (int i = 0; i <= 9; i++) { if (i != x) { a[i] = 1; } else { a[i] = 0; } } for (int i = 1; i <= 9; i++) { a[i] += a[i - 1]; } ll ans = 0; ll temp = n; vector<int> v; while (n) { v.push_back(n % 10); n /= 10; } for (int i = v.size() - 1; i >= 0; i--) { if (v[i] == 0) { ans = ans * 9; continue; } ans = ans * 9 + (a[v[i] - 1]); } cout << ans + 1 << '\n'; } int main() { int t; cin >> t; while (t--) { Totoro(); } return 0; }
|
## L
神秘规律题,找到第一个不能整除的。
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
|
#include <bits/stdc++.h> using namespace std; using ll = long long; const int N = 1e6 + 100; void Totoro() { ll n; cin >> n; ll ans; for (ll i = 2;; i++) { if (n % i != 0) { ans = i; break; } } cout << ans << '\n'; } int main() { int t = 1; cin >> t; while (t--) { Totoro(); } return 0; }
|
M
挺套路的一题,经典浮点数变整数求解。
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
|
#include <bits/stdc++.h> using namespace std; using ll = long long; const int N = 1e6+100; void Totoro() { int n; cin>>n; set<pair<int,int> >p; int ans=0; for(int i=1;i<=n;i++) { int x,y; cin>>x>>y; if(!p.count({x,y})) { p.insert({x,y}); } else { continue; } ans+=4; if(p.count({x,y-1})) { --ans; } if(p.count({x-1,y})) { --ans; } if(p.count({x+1,y})) { --ans; } if(p.count({x,y+1})) { --ans; } }
if(ans&1) { cout<<ans/2<<'.'<<5<<'\n'; } else { cout<<ans/2<<'\n'; }
} int main() { int t=1; while (t--) { Totoro(); } return 0; }
|