A题:Three Threes
题目大意:
给你一个数字 n,输出n 个数字 n
思路:
难度在于打开题目。
// Problem: A - Three Threes
// Contest: AtCoder - Toyota Programming Contest 2023#8(AtCoder Beginner Contest 333)
// URL: https://atcoder.jp/contests/abc333/tasks/abc333_a
// Memory Limit: 1024 MB
// Time Limit: 2000 ms
//
#include <bits/stdc++.h>
#define endl '\n'
using namespace std;
using ll = long long;
int main() {
ios::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
int n; cin >> n;
for (int i = 1; i <= n; i ++ ) cout << n;
return 0;
}
B题: Pentagon
题目大意:
给你一个正五边形的两条线段,判断是否相等。
思路:
我们可以发现,字符相差 2,3的长度为 根号3, 相差 1 ,4的长度为 1。
知道这点以后,解决就变得特别轻松了。
// Problem: B - Pentagon
// Contest: AtCoder - Toyota Programming Contest 2023#8(AtCoder Beginner Contest 333)
// URL: https://atcoder.jp/contests/abc333/tasks/abc333_b
// Memory Limit: 1024 MB
// Time Limit: 2000 ms
//
#include <bits/stdc++.h>
using namespace std;
int main() {
string s1, s2;
cin >> s1 >> s2;
int d = abs(s1[0] - s1[1]);
int d1 = abs(s2[0] - s2[1]);
if ((d == 1 || d == 4) && (d1 == 1 || d1 == 4)) puts("Yes");
else if ((d == 2 || d == 3) && (d1 == 2 || d1 == 3)) puts("Yes");
else puts("No");
return 0;
}
C题: Repunit Trio
题目大意:
给你1,11,111,1111....的这样关系的数,输出挑出3个组成的第N小的数。
比如第一小的是:
思路:
N最大是333,这不是让你暴力。
// Problem: C - Repunit Trio
// Contest: AtCoder - Toyota Programming Contest 2023#8(AtCoder Beginner Contest 333)
// URL: https://atcoder.jp/contests/abc333/tasks/abc333_c
// Memory Limit: 1024 MB
// Time Limit: 2000 ms
//
#include <bits/stdc++.h>
#define endl '\n'
using namespace std;
using ll = long long;
int main() {
ios::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
ll now = 1;
vector<ll> v;
for (int i = 1; i <= 18; i ++ ) {
v.push_back(now);
now = now * 10 + 1;
}
vector<ll> c;
for (int i = 0; i < 18; i ++ ) {
for (int j = 0; j < 18; j ++ ) {
for (int k = 0; k < 18; k ++ ) {
c.push_back(v[i] + v[j] + v[k]);
}
}
}
sort(c.begin(), c.end());
c.erase(unique(c.begin(), c.end()), c.end());
int n; cin >> n;
cout << c[n - 1] << endl;
return 0;
}
D题:Erase Leaves
题目大意:
你只能删除叶节点,删除一个记为1次操作,问直到删除掉1号节点的最小操作次数
思路:
首先我们知道这么几点:
如果1是叶节点,答案是1,因为可以直接删去1节点
如果1跟多边相连,我们一定不会去删去点数更多的,比如
2, 3,4跟1连一起,如果删去2,3,4号点的操作次数分别为a1,a2,a3。
如果要删去1号点,答案必定为a1 + a2 + a3 - max({a1, a2, a3})
所以我们用dfs统计删掉一个点要的操作次数,maxv存删除1号点一个儿子最多的操作次数
输出dfs - maxv即为答案。
// Problem: D - Erase Leaves
// Contest: AtCoder - Toyota Programming Contest 2023#8(AtCoder Beginner Contest 333)
// URL: https://atcoder.jp/contests/abc333/tasks/abc333_d
// Memory Limit: 1024 MB
// Time Limit: 2000 ms
//
#include <bits/stdc++.h>
using namespace std;
const int N = 3e5 + 9;
vector<int> e[N];
int main() {
ios::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
int n; cin >> n;
for (int i = 1; i <= n - 1; i ++ ) {
int u, v; cin >> u >> v;
e[u].push_back(v), e[v].push_back(u);
}
int maxv = -1;
vector<int> f(n + 1);
auto dfs = [&](auto dfs, int u, int pre) -> int {
if (f[u]) return f[u];
int sum = 1;
for (int x : e[u]) {
if (x == pre) continue;
int now = dfs(dfs, x, u);
sum += now;
if (u == 1) {
maxv = max(now, maxv);
}
}
return f[u] = sum;
};
cout << dfs(dfs, 1, -1) - maxv << endl;
return 0;
}
E题: Takahashi Quest
题目大意:
点击上方链接查看题目qwq,看一遍清楚些,这里就不过多赘述。
思路:
贪心。如果我们要用到药水,那么一定是用的是离它最近的1中可拾取的药水,这样才可以使得背
包的容量最小。我们可以用stack(栈)来存每个可以拾取药水的位置,要用到的时候用栈顶(最
近)的药水,如果栈空了,那么就是不可以的。
背包的最小大小,可以通过后续的use数组进行计算。
// Problem: E - Takahashi Quest
// Contest: AtCoder - Toyota Programming Contest 2023#8(AtCoder Beginner Contest 333)
// URL: https://atcoder.jp/contests/abc333/tasks/abc333_e
// Memory Limit: 1024 MB
// Time Limit: 2000 ms
//
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
typedef pair<int, int> PII;
int main() {
ios::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
int n; cin >> n;
vector<int> a(n);
stack<int> st[n + 1];
vector<bool> used(n);
bool ok = true;
for (int i = 0; i < n; i ++ ) {
int op, liq; cin >> op >> liq;
a[i] = op;
if (!ok) continue;
if (op == 1) {
st[liq].push(i);
}else {
if (st[liq].empty()) ok = false;
else {
used[st[liq].top()] = true;
st[liq].pop();
}
}
}
if (!ok) {
cout << -1 << endl;
return 0;
}
int bag = 0, ans = 0;
for (int i = 0; i < n; i ++ ) {
if (used[i]) {
bag += 1;
ans = max(bag, ans);
}else {
if (a[i] == 2) {
bag -= 1;
}
}
}
cout << ans << endl;
for (int i = 0; i < n; i ++ ) {
if (a[i] == 2) continue;
if (used[i]) cout << 1 << ' ';
else cout << 0 << ' ';
}
return 0;
}
写在最后
“你学这玩意有用吗?”
这是我的热爱
愿我们都走到彼岸