Codeforces Round #706 Editorial
1496A. Split it!
类回文判断,只要 k = 0 或者 \(s[1,k] 和 s[n - k + 1,n]\)是回文即可
特判情况 n < 2 * k + 1 为 NO
int main() {
ios_base::sync_with_stdio(false), cin.tie(0);
int _ = 1;
for (cin >> _; _--;) {
string s;
int n; ll k;
cin >> n >> k;
cin >> s;
bool f = true;
for (int i = 0; i < k && f; ++i) f = s[i] == s[n - i - 1]);
cout << (f && n >= 2 * k + 1 ? "YES\n" : "NO\n");
}
return 0;
}
1496B. Max and Mex
模拟,当 mex(a) < max(b) 时 必有 \(⌈\frac{a + b}2⌉ < b\) 则集合不一样的数可增加一,否则每进行一次操作 + 1
int main() {
ios_base::sync_with_stdio(false), cin.tie(0);
int _ = 1;
for (cin >> _; _--;) {
int n;
ll k;
cin >> n >> k;
vector<ll> a(n);
set<ll> s;
for (int i = 0; i < n; ++i) {
cin >> a[i];
s.insert(a[i]);
}
sort(a.begin(), a.end());
if (k == 0) {
cout << s.size() << "\n";
continue;
}
int i = 0;
ll b = 0;
while (b == a[i]) b++, i++;
if (b <= a[n - 1]) {
s.insert((b + a[n - 1] + 1) / 2);
cout << s.size() << "\n";
continue;
}
cout << s.size() + k << endl;
}
return 0;
}
1496C. Diamond Miner
将坐标绝对值化存入数组排序
\(\sqrt{(a-c)^2 +(b - d)^2} = \sqrt{a^2 + d^2}\) 要想有最小化,只能大值匹配大值
int main() {
ios_base::sync_with_stdio(false), cin.tie(0);
int _ = 1;
for (cin >> _; _--;) {
int n;
cin >> n;
vector<int> xx, yy;
for (int i = 0; i < 2 * n; ++i) {
int x, y;
cin >> x >> y;
if (x == 0) yy.push_back(abs(y));
else
xx.push_back((abs(x)));
}
sort(xx.begin(), xx.end());
sort(yy.begin(), yy.end());
double cnt = 0.0;
for (int i = 0; i < n; ++i) {
cnt += sqrt(1.0 * xx[i] * xx[i] + 1.0 * yy[i] * yy[i]);
}
cout << setprecision(15) << cnt << "\n";
}
return 0;
}
1496D. Let's Go Hiking
学习自 洛绫璃 dalao的思路
这是一道博弈题
由于只能存在一条最长链,否则先手站一条, 后手站一条, 先手必输
其次, 只有一条最长链, 先手和后手都会选在最长链上, 否则谁不在, 另一方直接获胜
在其 先手会在山峰, 否则后手直接卡死
故先手会选择在 最长链的最高端, 后手会选择最长链最远的地方, 保证和先手相隔 偶数个位置(保证两者都走最长链, 后手胜)
后手保证了先手最长链一定会输, 只能走最长链的反方向, 比较先手和后手能走的长度, 判断是否能先手赢
const int N = 1e5 + 5;
int t, n, maxn, ans, a[N], p1[N], p2[N];
int main() {
scanf("%d", &n);
for (int i = 1; i <= n; i++) {
scanf("%d", a + i);
p1[i] = (a[i] <= a[i - 1] || i == 1) ? 0 : (p1[i - 1] + 1);
maxn = max(maxn, p1[i]);
}
for (int i = n; i >= 1; i--)
p2[i] = (a[i] <= a[i + 1] || i == n) ? 0 : (p2[i + 1] + 1),
maxn = max(p2[i], maxn);
for (int i = 1; i <= n; i++)
if (p1[i] == p2[i] && p1[i] == maxn && maxn > 0 && ((maxn & 1) == 0)) {
ans = i;
break;
}
for (int i = 1; i <= n; i++)
if (ans != i && (p1[i] == maxn || p2[i] == maxn)) {
ans = 0;
break;
}
printf("%d", ans ? 1 : 0);
}
Codeforces Round #706 Editorial的更多相关文章
- Educational Codeforces Round 68 Editorial
题目链接:http://codeforces.com/contest/1194 A.Remove a Progre ...
- Codeforces Round #706 (Div. 2)B. Max and Mex __ 思维, 模拟
传送门 https://codeforces.com/contest/1496/problem/B 题目 Example input 5 4 1 0 1 3 4 3 1 0 1 4 3 0 0 1 4 ...
- Educational Codeforces Round 53 Editorial
After I read the solution to the problem, I found that my solution was simply unsightly. Solved 4 ou ...
- Educational Codeforces Round 39 Editorial B(Euclid算法,连续-=与%=的效率)
You have two variables a and b. Consider the following sequence of actions performed with these vari ...
- Codeforces Round #707 Editorial Div2 题解
CF1501 Div2 题解 CF1501A 这道题其实是一道英语阅读题,然后样例解释又不清晰,所以我看了好久,首先它告诉了你每个站点的预期到达时间 \(a_i\) ,以及每个站点的预期出发时间 \( ...
- Codeforces Round #590 (Div. 3) Editorial
Codeforces Round #590 (Div. 3) Editorial 题目链接 官方题解 不要因为走得太远,就忘记为什么出发! Problem A 题目大意:商店有n件商品,每件商品有不同 ...
- Codeforces Round #747 (Div. 2) Editorial
Codeforces Round #747 (Div. 2) A. Consecutive Sum Riddle 思路分析: 一开始想起了那个公式\(l + (l + 1) + - + (r − 1) ...
- Codeforces Round #367 (Div. 2) D. Vasiliy's Multiset (0/1-Trie树)
Vasiliy's Multiset 题目链接: http://codeforces.com/contest/706/problem/D Description Author has gone out ...
- Codeforces Round #367 (Div. 2) C. Hard problem(DP)
Hard problem 题目链接: http://codeforces.com/contest/706/problem/C Description Vasiliy is fond of solvin ...
- Codeforces Round #367 (Div. 2) B. Interesting drink (模拟)
Interesting drink 题目链接: http://codeforces.com/contest/706/problem/B Description Vasiliy likes to res ...
随机推荐
- jmeter二次开发自定义函数助手
需求:在工作中,需要使用唯一的字符串来作为订单ID,于是想到了UUID,要求uuid中不能有特殊字符包括横线,所以就有了重新写一个uuid进行使用: 准备:idea 依赖包: 注意事项:必须有包且包的 ...
- MYSQL EXPLAIN 执行计划
EXPLAIN 执行计划 有了慢查询语句后,就要对语句进行分析.一条查询语句在经过 MySQL 查询优化器的各种基于成本和规则的优化会后生成一个所谓的执行计划,这个执行计划展示了接下来具体执行查询的方 ...
- hbase报错 ERROR: org.apache.hadoop.hbase.ipc.ServerNotRunningYetException: Server is not running yet
hbase报错:hbase shell能打开 网页也能打开 但是一执行命令就开始报错. 原因:hadoop的安全模式打开. 解决方法:关闭安全模式 ,再重新启动HBase就可以了. 具体的命令: 1. ...
- 3 与HTTP相关的各种协议
目录 1 TCP/IP 2 DNS 3 URI/URL 4 HTTPS 5 代理 1 TCP/IP TCP/IP是网络世界最常用协议,HTTP通常运行在TCP/IP提供的可靠传输基础上 IP 协议是& ...
- ubuntu20.04安装goaccess实时对nginx日志进行分析
ubuntu20.04安装goaccess实时对nginx日志进行分析 goaccess可以对nginx日志进行分析,生成实时动态页面,同时通过nginx反向代理来解决WebSocket数据传输问题. ...
- Tampermonkey(油猴)的获取方法
介绍: Tampermonkey中有大量的脚本,可以方便我们在日常的上网使用. 有那么一句话说:没有了Tampermonkey(油猴)我都不知道该如何上网. 获取Tampermonkey的步骤: 1. ...
- 数据库系列:业内主流MySQL数据中间件梳理
数据库系列:MySQL慢查询分析和性能优化 数据库系列:MySQL索引优化总结(综合版) 数据库系列:高并发下的数据字段变更 数据库系列:覆盖索引和规避回表 数据库系列:数据库高可用及无损扩容 数据库 ...
- modeless dialog in html
<!DOCTYPE html> <html lang="zh_CN"> <head> <meta charset="UTF-8& ...
- Go 语言为什么建议多使用切片,少使用数组?
大家好,我是 frank,「Golang 语言开发栈」公众号作者. 01 介绍 在 Go 语言中,数组固定长度,切片可变长度:数组和切片都是值传递,因为切片传递的是指针,所以切片也被称为"引 ...
- spring-mvc 系列:HttpMessageConverter(@RequestBody、RequestEntity、@ResponseBody、@RestController、ResponseEntity、文件上传下载)
目录 一.@RequestBody 二.RequestEntity 三.@ResponseBody 四.SpringMVC处理json 五.@RestController 六.ResponseEnti ...