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 ...
随机推荐
- 在TCP四次挥手中,为什么客户端发送FIN后,还可以发送报文
在TCP四次挥手中,为什么客户端发送FIN后,还可以发送报文 首先回顾下四次挥手的过程. 第一次挥手:客户端停止发送数据,主动关闭 TCP 连接,处于FIN_WAIT1状态,等待服务端确认. 第二次挥 ...
- CLion安装与配置教程
一.下载并安装CLion 1.下载 1.官网: Download CLion 2.注意: 这里建议使用2021.1.3版本之前,为之后的使用便利而做打算. (这里以Windows系统为例,其他系统类似 ...
- javascript+php 实现blob加密视频(html video)
1.mp4地址加密为blob链接在html5的video标签展示 PHP: 1 $file_path = "...mp4"; //视频文件地址 2 ob_end_clean(); ...
- [USACO2007OPENS] City Horizon S
题目描述 Farmer John has taken his cows on a trip to the city! As the sun sets, the cows gaze at the cit ...
- Url参数解析组装工具类
import org.apache.commons.lang3.StringUtils; import java.util.HashMap; import java.util.Map; /** * @ ...
- MySQL运维15-一主一从读写分离
一.读写分离介绍 读写分离,是把数据库的读和写分开操作,以应对不同的数据库服务器.主数据库提供写操作,从数据库提供读操作,这样能有效的减轻单台数据库的压力. 二.一主一从原理 MySQL的主从复制是基 ...
- Intellij IDE 对接SVN
1.安装SVN(SVN安装包见附件) 注意安装时需要选择第二个选项进行安装 2.安装SVN中文包(见附件) 安装完成后随便找个文件夹右键确认SVN安装是否生效 3.Intellij IDE得Setti ...
- k8s在删除pod时优雅关闭sigterm信号传输失败
背景 随着云原生技术的流行,越来越多的应用选择容器化,容器化的话题自然离不开 Kubernetes .Pod 是 Kubernetes 中创建和管理的.最小的可部署的计算单元,一个 Pod 中有多个容 ...
- Java 新技术:虚拟线程使用指南(二)
虚拟线程是在 Java 21 版本中实现的一种轻量级线程.它由 JVM 进行创建以及管理.虚拟线程和传统线程(我们称之为平台线程)之间的主要区别在于,我们可以轻松地在一个 Java 程序中运行大量.甚 ...
- 文心一言 VS 讯飞星火 VS chatgpt (126)-- 算法导论11.1 1题
一.用go语言,假设一动态集合 S用一个长度为 m 的直接寻址表T来表示.请给出一个查找 S 中最大元素的过程.你所给的过程在最坏情况下的运行时间是多少? 文心一言,代码正常运行: 在这个问题中,我们 ...