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 ...
随机推荐
- 旺店通·企业奇门和用友BIP接口打通对接实战
旺店通·企业奇门和用友BIP接口打通对接实战 接通系统:旺店通·企业奇门 旺店通是北京掌上先机网络科技有限公司旗下品牌,国内的零售云服务提供商,基于云计算SaaS服务模式,以体系化解决方案,助力零售企 ...
- Django学习(一) 之 环境搭建
写在前面 最近比较迷AI绘图,那就上个图吧,我感觉还挺好看的. 可能会有人说,之前不一致分享的是flask吗,怎么突然改到django了? 这个问题问得好,开发环境遇到了一些小困难! 不过django ...
- SpringBoot Seata 死锁问题排查
现象描述:Spring Boot项目,启动的时候卡住了,一直卡在那里不动,没有报错,也没有日志输出 但是,奇怪的是,本地可以正常启动 好吧,姑且先不深究为什么本地可以启动而部署到服务器上就无法启动的问 ...
- 【WCH以太网接口系列芯片】基于CH395的组播应用
---------------------------------------------------------------------------------------------------- ...
- 听懂未来:AI语音识别技术的进步与实战
本文全面探索了语音识别技术,从其历史起源.关键技术发展到广泛的实际应用案例,揭示了这一领域的快速进步和深远影响.文章深入分析了语音识别在日常生活及各行业中的变革作用,展望了其未来发展趋势. 关注Tec ...
- LeetCode15:三数之和(双指针)
解题思路:常规解法很容易想到O(n^3)的解法,但是,n最大为1000,很显然会超时. 如何优化到O(n^2),a+b+c =0,我们只需要判断 a+b的相反数是否在数组中出现,而且元素的取值范围在 ...
- C++ Qt开发:StatusBar底部状态栏组件
Qt 是一个跨平台C++图形界面开发库,利用Qt可以快速开发跨平台窗体应用程序,在Qt中我们可以通过拖拽的方式将不同组件放到指定的位置,实现图形化开发极大的方便了开发效率,本章将重点介绍QStatus ...
- bash shell笔记整理——date命令
date命令初步了解 简单来说date的主要作用大多数用于以给定的格式来显示时间. 在后期我们写一些脚本当中也会使用到,比如说按照日期来给文件备份打包等. 下面我们来看看帮助信息: [root@ngi ...
- scrapy 请求meta参数使用案例-豆瓣电影爬取
num = 0 import scrapy from scrapy.http import HtmlResponse from scrapy_demo.items import DoubanItem ...
- 安装服务器提示A debugger has been found running in your system. Please, unload it from memory and restart
解决方法:运行msconfig,取消调试模式,重启电脑再安装