【CodeForces】Educational Codeforces Round 37 题解

本文详细解析了CodeForces Educational Round 37的比赛题目,包括A到G共7道题目。涉及的算法有模拟、队列模拟、排序、动态规划、并查集、树状数组以及莫比乌斯函数的应用。每个题目分别从思路要点、时间复杂度和代码实现三个方面进行阐述。

【比赛链接】

【题解链接】

【A】Water The Garden

【思路要点】

  • 按照题意模拟,或者简单计算一下均可。
  • 时间复杂度\(O(N)\)。

【代码】

#include<bits/stdc++.h>
using namespace std;
const int MAXN = 5005;
template <typename T> void read(T &x) {
	x = 0; int f = 1;
	char c = getchar();
	for (; !isdigit(c); c = getchar()) if (c == '-') f = -f;
	for (; isdigit(c); c = getchar()) x = x * 10 + c - '0';
	x *= f;
}
template <typename T> void write(T x) {
	if (x < 0) x = -x, putchar('-');
	if (x > 9) write(x / 10);
	putchar(x % 10 + '0');
}
template <typename T> void writeln(T x) {
	write(x);
	puts("");
}
int a[MAXN];
int main() {
	int T; read(T);
	while (T--) {
		int n, k;
		read(n), read(k);
		for (int i = 1; i <= k; i++)
			read(a[i]);
		int ans = max(a[1], n + 1 - a[k]);
		for (int i = 1; i <= k - 1; i++) {
			int tmp = a[i + 1] - a[i];
			ans = max(ans, 1 + tmp / 2);
		}
		writeln(ans);
	}
	return 0;
}


【B】Tea Queue

【思路要点】

  • 维护当前的排队的队列,模拟过程即可。
  • 时间复杂度\(O(N*max(r_{i}))\)。

【代码】

#include<bits/stdc++.h>
using namespace std;
const int MAXN = 8005;
template <typename T> void read(T &x) {
	x = 0; int f = 1;
	char c = getchar();
	for (; !isdigit(c); c = getchar()) if (c == '-') f = -f;
	for (; isdigit(c); c = getchar()) x = x * 10 + c - '0';
	x *= f;
}
template <typename T> void write(T x) {
	if (x < 0) x = -x, putchar('-');
	if (x 
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值