【CodeForces】CodeForces Round #475 (Div. 1 + Div. 2) 题解

本文详细解析了CodeForces Round #475 (Div. 1 + Div. 2) 的比赛题目,包括Div.2的A、B、C/D、E题目和Div.1的A、B、D、E题目。通过思路要点和代码展示,介绍了每道题目的解题思想和解决方案,涉及时间复杂度分析,如线性、平方和多项式时间复杂度的算法。
摘要由CSDN通过智能技术生成

【比赛链接】

【题解链接】

【Div.2 A】Splits

【思路要点】

  • 由于我们希望得到尽可能不同的权值,我们可以考虑在拆分的开头放置若干个2,然后放1填补剩余的数字。
  • 不难发现答案等于\(\lfloor\frac{N}{2}\rfloor+1\)。
  • 时间复杂度\(O(1)\)。

【代码】

#include<bits/stdc++.h>
using namespace std;
const int MAXN = 100005;
template <typename T> void chkmax(T &x, T y) {x = max(x, y); }
template <typename T> void chkmin(T &x, T y) {x = min(x, y); } 
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 main() {
	int n; read(n);
	writeln(n / 2 + 1);
	return 0;
}

【Div.2 B】Messages

【思路要点】

  • 考虑到阅读信息的收益是关于时间的一次函数,最值一定可以在端点处取到。
  • 在收到信息立刻阅读与留到最后阅读两个方案中取较大者即可。
  • 时间复杂度\(O(N)\)。

【代码】

#include<bits/stdc++.h>
using namespace std;
const int MAXN = 100005;
template <typename T> void chkmax(T &x, T y) {x = max(x, y); }
template <typename T> void chkmin(T &x, T y) {x = min(x, y); } 
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 main() {
	int n, A, B, C, T, ans = 0;
	read(n), read(A), read(B), read(C), read(T);
	for (int i = 1; i <= n; i++) {
		int x; read(x);
		ans += A;
		if (C >= B) ans += (T - x) * (C - B);
	}
	writeln(ans);
	return 0;
}

【Div.2 C/Div.1 A】Al

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值