Vp AtCoder Beginner Contest 333

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小的数。

比如第一小的是: 1 + 1 + 1 = 3

思路:

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;
}

写在最后

“你学这玩意有用吗?”

这是我的热爱

愿我们都走到彼岸

 

  • 5
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值