【AtCoder】Tokio Marine & Nichido Fire Insurance Programming Contest 2020

本文介绍了AtCoder的Tokio Marine & Nichido Fire Insurance Programming Contest 2020比赛,包括比赛链接和官方题解。讨论了六个问题,包括:Nickname(简单的字符串操作)、Tag(简单的数学比较)、Lamps(状态模拟)、Knapsack Queries on a tree(动态规划与树结构)、O(rand)(组合计数与FWT)和Triangles(几何与欧几里得算法)。每个问题都分析了时间复杂度和解决方案。
摘要由CSDN通过智能技术生成

比赛链接

点击打开链接

官方题解

点击打开链接

Problem A. Nickname

输出 s 1 s 2 s 3 s_1s_2s_3 s1s2s3 即可。
时间复杂度 O ( ∣ S ∣ ) O(|S|) O(S)

#include<bits/stdc++.h>
using namespace std;
const int MAXN = 3e5 + 5;
typedef long long ll;
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;
}
char s[MAXN];
int main() {
	scanf("%s", s + 1), s[4] = 0;
	printf("%s\n", s + 1);
	return 0;
}

Problem B. Tag

判断 T × ( V − W ) T\times (V-W) T×(VW) ∣ A − B ∣ |A-B| AB 的大小关系即可。
时间复杂度 O ( 1 ) O(1) O(1)

#include<bits/stdc++.h>
using namespace std;
const int MAXN = 3e5 + 5;
typedef long long ll;
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;
}
int main() {
	int a, v, b, w, t;
	read(a), read(v), read(b), read(w), read(t);
	int dist = abs(a - b);
	if (v > w && 1ll * t * (v - w) >= dist) puts("YES");
	else puts("NO");
	return 0;
}

Problem C. Lamps

考虑初始时 A i = 0 A_i=0 Ai=0 的情况,则经过 O ( L o g N ) O(LogN) O(LogN) 次操作后,应当有 A i = N A_i=N Ai=N
因此,有效操作的轮数不会超过 O ( L o g N ) O(LogN) O(LogN) 。模拟,直到 A i = N A_i=N Ai=N 或是操作次数用尽即可。

时间复杂度 O ( N L o g N ) O(NLogN) O(NLogN)

#include<bits/stdc++.h>
using namespace std;
const int MAXN = 2e5 + 5;
typedef long long ll;
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;
}
int n, k, a[MAXN];
bool work() {
	static int s[MAXN];
	memset(s, 0, sizeof(s));
	for (int i = 1; i <= n; i++) {
		int l = max(1, i - a[i]), r = min(n, i + a[i]);
		s[l]++, s[r + 1]--;
	}
	bool res = false;
	for (int i = 1; i <= n; i++) {
		s[i] += s[i - 1];
		if (s[i] != a[i]) {
			res = true;
			a[i] = s[i];
		}
	}
	return res;
}
int main() {
	read(n), read(k);
	for (int i = 1; i <= n; i++)
		read(a[i]);
	for (int i = 1; i <= k; i++)
		if (!work()) break;
	for (int i = 1; i <= n; i++)
		printf("%d ", a[i]);
	printf("\n");
	return 0;
}

Problem D. Knapsack Queries on a tree

一种可行的暴力是记 d p i , j dp_{i,j} dp

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值