1496A. Split it!

类回文判断,只要 k = 0 或者 \(s[1,k] 和 s[n - k + 1,n]\)是回文即可

特判情况 n < 2 * k + 1NO

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. 聊聊分布式 SQL 数据库Doris(七)

    LSM-Tree Doris的存储结构是类似LSM-Tree设计的,因此很多方面都是通用的,先阅读了解LSM相关的知识,再看Doris的底层存储与读取流程会清晰透彻很多,如下是几个关键的设计: SST ...

  2. 【uniapp】学习笔记day02 | uniapp搭建

    起因:需要做一个小程序,家人们谁懂啊,老师我真的不会做,由于懒得看视频学习,于是只能看博客学习了. uniapp 好处: 1.不用关心适配问题 2.可以发布到各大平台的小程序 3.上手容易,使用vue ...

  3. 【LOJ NOI Round#2 Day1 T1】单枪匹马(矩阵乘法)

    题目传送门 操作二要求的东西是一个循环迭代的东西,手推相邻两项找下规律,发现相邻两项的分子分母间含有线性关系,考虑用矩阵乘法求解.对于 \([1,n]\)的询问,从后往前倒推, \(x_{n-1}=a ...

  4. Kotlin协程系列(三)

    1.前言 前面两节,我们运用了kotlin提供的简单协程去实现了一套更易用的复合协程,这些基本上是以官方协程框架为范本进行设计和实现的.虽然我们还没有直接接触kotlin官方协程框架,但对它的绝大多数 ...

  5. Go笔记(1)-变量的详细用法

    变量 (1)变量的定义 Go语言是静态类型的语言,所有类型都需要明确的定义. var是声明变量的关键字 使用格式:var 变量名 变量类型 变量命名规范:遵循驼峰格式,首个单词小写,每个新单词的首字母 ...

  6. 文心一言 VS 讯飞星火 VS chatgpt (153)-- 算法导论12.2 9题

    九.用go语言,设 T 是一棵二叉搜索树,其关键字互不相同;设 x 是一个叶结点,y 为其父结点.证明: y.key 或者是 T 树中大于 x.key 的最小关键字,或者是 T 树中小于 x.key ...

  7. .NET 8上进行PDF合并

    前言:在.NET 8中使用itext7需安装 itext7 和 itext7.bouncy-castle-fips-adapter 两个Nuget包,或者使用Aspose.PDF.PdfSharpCo ...

  8. Python——第四章:函数的递归调用

    递归:  函数自己调用自己 递归如果没有任何东西拦截的话. 它默认就是一个死循环 def func() func() func() 因此递归调用的时候需要有判断,来退出循环 def func() if ...

  9. 玩转Python:处理音频文件,两个非常重要的库,很实用,附代码

    pyaudio和sounddevice都是用于Python中音频处理和流的库,允许用户通过他们的API录制.播放和处理音频数据.下面是对这两个库的简要介绍: PyAudio PyAudio 提供了 P ...

  10. libGDX游戏开发之NPC敌人事件(六)

    libGDX系列,游戏开发有unity3D巴拉巴拉的,为啥还用java开发?因为我是Java程序员emm-国内用libgdx比较少,多数情况需要去官网和google找资料,相互学习的可以加我联系方式. ...