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的更多相关文章

  1. Educational Codeforces Round 68 Editorial

    题目链接:http://codeforces.com/contest/1194                                            A.Remove a Progre ...

  2. 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 ...

  3. Educational Codeforces Round 53 Editorial

    After I read the solution to the problem, I found that my solution was simply unsightly. Solved 4 ou ...

  4. Educational Codeforces Round 39 Editorial B(Euclid算法,连续-=与%=的效率)

    You have two variables a and b. Consider the following sequence of actions performed with these vari ...

  5. Codeforces Round #707 Editorial Div2 题解

    CF1501 Div2 题解 CF1501A 这道题其实是一道英语阅读题,然后样例解释又不清晰,所以我看了好久,首先它告诉了你每个站点的预期到达时间 \(a_i\) ,以及每个站点的预期出发时间 \( ...

  6. Codeforces Round #590 (Div. 3) Editorial

    Codeforces Round #590 (Div. 3) Editorial 题目链接 官方题解 不要因为走得太远,就忘记为什么出发! Problem A 题目大意:商店有n件商品,每件商品有不同 ...

  7. Codeforces Round #747 (Div. 2) Editorial

    Codeforces Round #747 (Div. 2) A. Consecutive Sum Riddle 思路分析: 一开始想起了那个公式\(l + (l + 1) + - + (r − 1) ...

  8. 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 ...

  9. Codeforces Round #367 (Div. 2) C. Hard problem(DP)

    Hard problem 题目链接: http://codeforces.com/contest/706/problem/C Description Vasiliy is fond of solvin ...

  10. Codeforces Round #367 (Div. 2) B. Interesting drink (模拟)

    Interesting drink 题目链接: http://codeforces.com/contest/706/problem/B Description Vasiliy likes to res ...

随机推荐

  1. Mysql中的FOREIGN_KEY_CHECKS方法【外键约束作用】

    一.命令行 首先FOREIGN_KEY_CHECKS方法的作用是用来启动和关闭外键约束的方法. 二.外键约束 即数据库中两个数据表之间的某个列建立的一种联系.MySQL通过外键约束的引入,可以使得数据 ...

  2. 【让AI女友跟我表白】大白话说Python+Flask入门(四)Flask Sijax的使用

    写在前面 先吐槽两句,搞个mysql安装配置弄了4个小时,怎么都是外网无法访问,我靠,我特么也是服了. 当然,后来我投降了,明天再说,学什么不是学,娘的,换个方向,状态依然在! Sijax是什么? 代 ...

  3. 为什么MySQL不建议使用delete删除数据?

    MySQL并不直接建议禁止使用DELETE语句删除数据,但是在某些情况下,使用DELETE可能会带来一些潜在的问题,特别是在大型数据库中. 下面我将详细介绍为什么在某些情况下MySQL不建议过度使用D ...

  4. 【布局技巧】Flex 布局下居中溢出滚动截断问题

    在页面布局中,我们经常会遇到/使用这么一类常见的布局,也就是列表内容水平居中于容器中,像是这样: <ul class="g-contaner"> <li>& ...

  5. springMvc_控制台中文乱码问题

    Post方法解决控制台乱码 @Override protected Filter[] getServletFilters() { CharacterEncodingFilter filter = ne ...

  6. ROW_NUMBER 开窗函数优化方案(Oracle && PostgreSQL 性能比对)

    帮朋友优化一条很简单的窗口函数 ROW_NUMBER() OVER() , Oracle 迁移 PostgreSQL项目. 原始SQL和执行计划 STUDENT_BAK 表我模拟的数据,3千万行数据. ...

  7. 笔记本安装linux

    下载 桌面版 Ubuntu 镜像 服务器版 Ubuntu 镜像 使用 Balena Etcher 制作系统安装盘 (1)官方网站下载: 点我下载 (2)下载完毕软件之后,打开软件,选择我们下载好的系统 ...

  8. java判断两个日期是否连续

    使用java判断两个日期的天是否连续 import java.text.SimpleDateFormat; import java.util.Date; /** * @author lingkang ...

  9. Git commit emoji 对照表

    emoji emoji代码 commit说明 (调色板) :art: 改进代码结构/代码格式 ️ (闪电) :zap: 提升性能 (赛马) :racehorse: 提升性能 (火焰) :fire: 移 ...

  10. git blame 用法小记

    1.概述 git管理的代码仓库,在协作开发中不可避免地会出现代码冲突,或者有新手错误地提交代码.出现问题不可怕,可怕的是找不到问题出在哪里.有时候找到出问题的代码,却不知道是谁提交的.git提供了一个 ...