Codeforces Round #707 (Div. 2, based on Moscow Open Olympiad in Informatics Editorial
Codeforces Round #707 (Div. 2, based on Moscow Open Olympiad in Informatics)
Problem 1501A. Alexey and Train
按题意,比较到站的最大值.
using ll = long long;
int a[105], b[105], c[105];
int main() {
// ios_base::sync_with_stdio(false), cin.tie(0);
int _;
for (cin >> _; _--;) {
int n, s = 0;
scanf("%d", &n);
for (int i = 1; i <= n; i++) scanf("%d%d", &a[i], &b[i]);
for (int i = 1; i <= n; i++) {
scanf("%d", &c[i]), s += a[i] - b[i - 1] + c[i];
if (i == n) break;
s = max(s + (b[i] - a[i] + 1) / 2, b[i]);
}
cout << s << "\n";
}
return 0;
}
Problem 1501B. Napoleon Cake
从后往前比较.
int arr[200001];
int res[200001];
int main() {
ios_base::sync_with_stdio(false), cin.tie(0);
int _ = 1;
for (cin >> _; _--;) {
int n, i, mn = 1e9;
cin >> n;
for (i = 1; i <= n; i++) cin >> arr[i];
for (i = n; i >= 1; i--) {
mn = min(mn, i - arr[i]);
res[i] = (mn < i);
}
for (i = 1; i <= n; i++) cout << res[i] << " ";
cout << endl;
}
return 0;
}
Problem 1501C. Going Home
把两数之和想象成坐标,x 和 y
使用双指针然后存储和存储一下,如果能匹配并且 坐标不重复即可输出。
数组开大点,这个导致WA好几次了....
const int N = 5000003;
int x[N], y[N], a[N];
int main() {
ios_base::sync_with_stdio(false), cin.tie(0);
int n;
cin >> n;
for (int i = 1; i <= n; ++i) cin >> a[i];
for (int i = 1; i <= n; ++i)
for (int j = i + 1; j <= n; ++j) {
int s = a[i] + a[j];
if (x[s] && y[s] && x[s] != i && y[s] != j && x[s] != j &&
y[s] != i) {
cout << "YES\n";
cout << i << " " << j << " " << x[s] << " " << y[s] << "\n";
return 0;
}
x[s] = i;
y[s] = j;
}
cout << "NO\n";
return 0;
}
分类:
刷题笔记: CF
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 探究高空视频全景AR技术的实现原理
· 理解Rust引用及其生命周期标识(上)
· 浏览器原生「磁吸」效果!Anchor Positioning 锚点定位神器解析
· 没有源码,如何修改代码逻辑?
· 一个奇形怪状的面试题:Bean中的CHM要不要加volatile?
· 分享4款.NET开源、免费、实用的商城系统
· Obsidian + DeepSeek:免费 AI 助力你的知识管理,让你的笔记飞起来!
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· 白话解读 Dapr 1.15:你的「微服务管家」又秀新绝活了
· 全程不用写代码,我用AI程序员写了一个飞机大战
2020-03-15 LeetCode | 第180场周赛--5356矩阵中的幸运数