2024 University of Shanghai for Science and Technology(USST) Freshman Challenge Contest

1|0A. 我是组题人


#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; vector<int> a(n); for (auto &i: a) cin >> i; vector<int> p(n); iota(p.begin(), p.end(), 0); ranges::sort(p, [&](const int x, const int y) -> bool { if (a[x] != a[y]) return a[x] < a[y]; return x < y; }); for (auto i: p) cout << i + 1 << " "; }

2|0C. 小学题


m22+(n+m)(nm)2=n22

发现阴影部分的面积和m无关。

#include <bits/stdc++.h> using namespace std; using i64 = long long; void solve() { i64 n, l, r; cin >> n >> l >> r; cout << l << "\n"; return; } int main() { ios::sync_with_stdio(false), cin.tie(nullptr); int T; cin >> T; while (T--) solve(); }

3|0E. 昨日方舟


模拟题

#include <bits/stdc++.h> using namespace std; using i32 = int32_t; using i64 = long long; #define int i64 using vi = vector<int>; using pii = pair<int, int>; const int inf = INT_MAX; i32 main() { ios::sync_with_stdio(false), cin.tie(nullptr); int n, m, k; cin >> n >> m >> k; vector g(n, vector<char>(m, 'O')); for (auto &gi: g) for (auto &gij: gi) { int x; cin >> x; if (x == 0) gij = 'X'; } auto dx = [](char x) { if (x == 'u') return -1; if (x == 'd') return 1; return 0; }; auto dy = [](char y) { if (y == 'l') return -1; if (y == 'r') return 1; return 0; }; vector lst(n, vector<int>(m, inf)); for (; k; k--) { int x, y; char t; cin >> x >> y >> t, x--, y--; if (g[x][y] != 'O') continue; int fx = x + dx(t), fy = y + dy(t); if (fx >= 0 and fy >= 0 and fx < n and fy < m and 'a' <= g[fx][fy] and g[fx][fy] <= 'z') { g[fx][fy] += 'A' - 'a'; } else { g[x][y] = t, lst[x][y] = k; int ret = inf; for (int gx, gy; auto i: "udlr") { gx = x - dx(i), gy = y - dy(i); if (gx < 0 or gy < 0 or gx >= n or gy >= m)continue; if (g[gx][gy] != i) continue; ret = min(ret, lst[gx][gy]); } if (ret == inf) continue; g[x][y] += 'A' - 'a'; for (int gx, gy; auto i: "udlr") { gx = x - dx(i), gy = y - dy(i); if (gx < 0 or gy < 0 or gx >= n or gy >= m)continue; if (lst[gx][gy] != ret) continue; g[gx][gy] = 'O'; break; } } } for (auto &gi: g) { for (auto &gij: gi) cout << gij; cout << "\n"; } return 0; }

4|0G. 石子游戏


打表找规律,发现先手必胜的情况是连续的若干段。

第一段的长度是t1=n,之后每一段长度是ti=2ti

第一段的与 0 的间隔是d1=2(n+1),之后每一段与前一段的间隔都是di=2di1

第一段的结尾在p1=d12,之后每一段的结尾在pi=pi1+di1

#include <bits/stdc++.h> using namespace std; using i32 = int32_t; using i64 = long long; #define int i64 using vi = vector<int>; using pii = pair<int, int>; map<pii, int> g; int sg(int n, int k) { if (g.count(pair(n, k))) return g[pair(n, k)]; for (int i = 1; i <= n; i++) { if (n + i > k) break; if (sg(n + i, k) == 0) return g[pair(n, k)] = 1; } return g[pair(n, k)] = 0; } void test() { for (int i = 3; i <= 80; i++) { cout << i << " " << sg(3, i) << "\n"; } exit(0); } void solve() { int n, k; cin >> n >> k; int d = (n + 1) * 2, p = d - 2, t = n; while (p < k) { p += d; d *= 2, t *= 2; } if (k > p - t) cout << "Alice\n"; else cout << "Bob\n"; } i32 main() { ios::sync_with_stdio(false), cin.tie(nullptr); int T; cin >> T; while (T--) solve(); return 0; }

5|0I. 纠缠之圆


主要考虑圆心距离与半径之间的关系。

首先如果重合有无限条切线。

如果圆心距大于半径之和有 4 条

如果圆心距等于半径之和有 3 条

如果圆心距大于半径之差有 2 条

如果圆心距等于半径之差有 1 条

剩下情况有0 条

逐一判断就好

#include <bits/stdc++.h> using namespace std; using i64 = long long; void solve() { i64 o1x, o2x, o1y, o2y, o1r, o2r; cin >> o1x >> o1y >> o1r; cin >> o2x >> o2y >> o2r; if (o1x == o2x and o1y == o2y and o1r == o2r) { cout << "-1\n"; return; } i64 d = (o1x - o2x) * (o1x - o2x) + (o1y - o2y) * (o1y - o2y); i64 r1 = (o1r + o2r) * (o1r + o2r); i64 r2 = (o1r - o2r) * (o1r - o2r); if (d > r1) { cout << 4 << "\n"; } else if (d == r1) { cout << 3 << "\n"; } else if (d > r2) { cout << 2 << "\n"; } else if (d == r2) { cout << 1 << "\n"; } else { cout << 0 << "\n"; } } int main() { ios::sync_with_stdio(false), cin.tie(nullptr); int T; cin >> T; while (T--) solve(); }

6|0J. 上学


题面的意思,可以抽象为,选三个点,且三个点不在一条链上方案数,这里链指的是从根到叶子的一条路径。

我们可以用总方案数Cn3减去三个点在一条链方案数。

我们可以枚举三个点中深度最深的点,然后从这个点到根路径上的点有d个,那么剩下两个点的选择方案就是d(d1)2

#include <bits/stdc++.h> using namespace std; using i32 = int32_t; using i64 = long long; #define int i64 using vi = vector<int>; using pii = pair<int, int>; i32 main() { ios::sync_with_stdio(false), cin.tie(nullptr); int n; cin >> n; vector<vi> e(n + 1); for (int i = 1, x, y; i < n; i++) { cin >> x >> y; e[x].push_back(y); e[y].push_back(x); } vi dis(n + 1); auto dfs = [&](auto &&self, int x, int fa) -> void { for (auto y: e[x]) { if (y == fa) continue; dis[y] = dis[x] + 1; self(self, y, x); } }; dfs(dfs, 1, -1); int res = n * (n - 1) * (n - 2) / 6; for (int i = 1; i <= n; i++) res -= dis[i] * (dis[i] - 1) / 2; cout << res; return 0; }

7|0K. 环形数组(easy)


维护当前点的坐标和移动方向,暴力的把图填出来就好了。

#include <bits/stdc++.h> using namespace std; using i64 = long long; const vector<int> dx = {0, 1, 0, -1}, dy = {1, 0, -1, 0}; int main() { ios::sync_with_stdio(false), cin.tie(nullptr); int n, m; cin >> n >> m; vector a(n, vector<int>(m)); int x = 0, y = 0, d = 0; for (int i = 1, N = n * m, fx, fy; i <= N; i++) { a[x][y] = i; fx = x + dx[d], fy = y + dy[d]; if (fx < 0 or fy < 0 or fx >= n or fy >= m or a[fx][fy] != 0) { d = (d + 1) % 4; fx = x + dx[d], fy = y + dy[d]; } x = fx, y = fy; } for (auto ai: a) { for (auto aij: ai) cout << aij << " "; cout << "\n"; } return 0; }

8|0L. 环形数组(hard)


我们一圈一圈的考虑,第i的总个数是2n+2m+48i,前i圈的总个数是(2n+2m4i)i。这样我们可以二分出应该在第几圈然后暴力判断最后一圈就好了。

#include <bits/stdc++.h> using namespace std; using i32 = int32_t; using i64 = long long; #define int i64 using vi = vector<int>; using pii = pair<int, int>; void solve() { int n, m, t; cin >> n >> m >> t, t--; int l = 1, r = min(n, m), i = -1; while (l <= r) { int mid = (l + r) / 2; if ((2 * n + 2 * m - 4 * mid) * mid >= t) i = mid, r = mid - 1; else l = mid + 1; } int x = i, y = i; i--; t -= (2 * n + 2 * m - 4 * i) * i, n -= 2 * i + 1, m -= 2 * i + 1; if (t > 0) y += min(m, t), t -= min(m, t); if (t > 0) x += min(n, t), t -= min(n, t); if (t > 0) y -= min(m, t), t -= min(m, t); if (t > 0) x -= min(n, t), t -= min(n, t); cout << x << " " << y << "\n"; return; } i32 main() { ios::sync_with_stdio(false), cin.tie(nullptr); int T; cin >> T; while (T--) solve(); return 0; }

9|0M. 蔡光数组


#include <bits/stdc++.h> using namespace std; using i64 = long long; int main() { ios::sync_with_stdio(false), cin.tie(nullptr); int a, b, c, d; cin >> a >> b >> c >> d; if (a != b and b == c and a != d and b != d) { cout << "Yes\n"; } else { cout << "No\n"; } }

__EOF__

本文作者PHarr
本文链接https://www.cnblogs.com/PHarr/p/18413986.html
关于博主:前OIer,SMUer
版权声明CC BY-NC 4.0
声援博主:如果这篇文章对您有帮助,不妨给我点个赞
posted @   PHarr  阅读(23)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 震惊!C++程序真的从main开始吗?99%的程序员都答错了
· 【硬核科普】Trae如何「偷看」你的代码?零基础破解AI编程运行原理
· 单元测试从入门到精通
· 上周热点回顾(3.3-3.9)
· winform 绘制太阳,地球,月球 运作规律
点击右上角即可分享
微信分享提示