写在前边

链接:Codeforces Round #706 (Div. 2)

\(A,B,C,D\),这场有点简单,不过由于A写炸了后边题连看都没看就溜了,就从上大分变成了掉大分

A. Split it!

链接:A题链接

题目大意:

给定一个字符串\(s\),和一个数字\(k\),那么\(a_i\)是\(s\)的一个子串,\(R(a_i)\)代表\(a_i\)的逆序,问是否满足:

\[s = a_1 + a_2 + ... + a_k + a_{k + 1} + R(a_k) + R(a_{k - 1}) + ... + R(a_1)
\]

思路

首先要知道,有一个单独的\(a_{k + 1}\)部分,那么这部分,根本无所谓,但是对于它的两侧必然要是回文的,一开始就拽着回文串不放了,思维定势,以为全串必然要是回文才行,所以写炸了,所以只需要判断\(s[1, k]\)是否等于\(s[n - k + 1, n]\)(下标从1开始)即可,还要注意的是如果这个串的长度为偶数,那么\(k\)必然不能等于\(\cfrac{s.size()}{2}\),

代码:

#include <iostream>
#include <cstring>
#include <algorithm>
#include <cstdio>
#include <vector>
#include <map>
#include <cstring> //#pragma GCC optimize(2)
//#pragma GCC optimize(3,"Ofast","inline") using namespace std; #define Inf 0x3f3f3f3f
#define PII pair<int, int>
#define P2LL pair<long long, long long>
#define endl '\n'
#define pub push_back
#define pob pop_back typedef long long LL;
typedef unsigned long long ULL;
typedef vector<long long> VLL;
typedef vector<int> VI; const int Mod = 10000007; LL gcd(LL a, LL b) {
return b ? gcd(b, a % b) : a;
} void solve() {
string s;
int n, k;
cin >> n >> k;
cin >> s;
if (k == 0) {
puts("YES");
return;
} //这题并不一定要求中间是回文的
if (s.size() % 2 == 0 && k == s.size() / 2) {
puts("NO");
return;
}
bool flag = true;
for (int i = 0; i < k; i++) {
if (s[i] != s[s.size() - 1 - i]) {
flag = false;
break;
}
}
puts(flag ? "YES" : "NO");
} int main()
{
//ios::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);
int t;
scanf("%d", &t);
while (t--) {
solve();
}
return 0;
}

B. Max and Mex

链接:B题链接

题目大意:

给定一个序列\(s\),我们可以进行\(k\)次操作,每次操作是添加一个\(\lceil \cfrac{a + b}{2} \rceil\),\(a = mex(s)\), \(b = max(s)\),\(max\)就是序列中最大的数字,\(mex\)表示序列中最小不存在的非负整数,例如在序列\(0,1,2,4\)中,那么\(mex = 3\),问\(k\)次插入后,\(S\)中不同数字的个数有多少。

思路

先找到第一个\(mex\),如果\(mex <= max(S)\),可以发现,插入一个\(\lceil \cfrac{a + b}{2} \rceil\),永远不会出现这个数,因此,mex就永远不会变化,与此同时插入的值也永远不会大于max,所以mex与max不变,那么序列中不同数的个数最多就加1,用一个set维护就好。

如果\(mex == max(S)\),即假设序列为\(0,1,2,3\),那么第一个\(mex\)就是\(4\),所以\(\lceil \cfrac{a + b}{2} \rceil\)算出来就是\(mex\),就插入一个新值,所以这种情况下,有多少个\(k\),就插入多少个新值。

注意:取最大值的时候要看要注意数组并不一定是严格有序的啊!!

代码:

#include <iostream>
#include <cstring>
#include <algorithm>
#include <cstdio>
#include <vector>
#include <map>
#include <cstring>
#include <set> //#pragma GCC optimize(2)
//#pragma GCC optimize(3,"Ofast","inline") using namespace std; #define Inf 0x3f3f3f3f
#define PII pair<int, int>
#define P2LL pair<long long, long long>
#define endl '\n'
#define pub push_back
#define pob pop_back typedef long long LL;
typedef unsigned long long ULL;
typedef vector<long long> VLL;
typedef vector<int> VI; const int Mod = 10000007; LL gcd(LL a, LL b) {
return b ? gcd(b, a % b) : a;
} const int N = 1e5 + 10;
int a[N]; //题目没说给有序数组大哥
void solve() {
int n, k;
scanf("%d%d", &n, &k);
multiset<int> st2; //记录没有的数字 最小的数字
set<int> st3; for (int i = 0; i < n; i++) scanf("%d", &a[i]); sort(a, a + n);
for (int i = 0; i < n; i++) {
st3.insert(a[i]);
st2.insert(a[i]);
} if (k == 0) {
cout << st3.size() << endl;
return;
} int m = 0;
for (auto &it : st2) {
if (m != it) {
break;
}
m++;
} if (m > a[n - 1]) cout << n + k << endl;
else {
st3.insert((m + a[n - 1] + 1) / 2);
cout << st3.size() << endl;
}
} int main()
{
//ios::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);
int t;
scanf("%d", &t);
while (t--) {
solve();
} return 0;
}

C. Diamond Miner

链接:C题链接

题目大意:

不说了,太简单了。

思路

排序,贪心求值就好了

代码:

#include <iostream>
#include <cstring>
#include <algorithm>
#include <cstdio>
#include <vector>
#include <map>
#include <cstring>
#include <cmath> //#pragma GCC optimize(2)
//#pragma GCC optimize(3,"Ofast","inline") using namespace std; #define Inf 0x3f3f3f3f
#define PII pair<int, int>
#define P2LL pair<long long, long long>
#define endl '\n'
#define pub push_back
#define pob pop_back typedef long long LL;
typedef unsigned long long ULL;
typedef vector<long long> VLL;
typedef vector<int> VI; const int Mod = 10000007; const int N = 1e5 + 10; void solve() {
int n;
scanf("%d", &n);
vector<int> a, b;
for (int i = 0; i < n * 2; i++) {
int x, y;
scanf("%d%d", &x, &y);
if (x == 0) b.push_back(abs(y));
if (y == 0) a.push_back(abs(x));
} sort(a.begin(), a.end());
sort(b.begin(), b.end()); double res = 0.0;
for (int i = 0; i < n; i++) {
res += sqrt((LL) a[i] * a[i] + (LL) b[i] * b[i]); //千万不要忘记long long
}
printf("%.15lf\n", res);
} int main()
{
//ios::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);
int t;
scanf("%d", &t);
while (t--) {
solve();
} return 0;
}

D. Let's Go Hiking

链接:D题链接

题目大意:

给题目大意转化一下就是,小\(A\)只能走一条单调递减序列,小\(B\)只能走一条单调递减序列,直到到某个人走的时候这个人无路可走了那么他就输了。题目中为小\(A\)先选一个起点,然后小B后选一个起点,接下来,小A先做决策,再B做决策,两者选择永远最优,问最后小A。

思路

是一道博弈论的题目,两个人都是在单调的路上走,并且对于\(B\)来说,肯定要想办法让A输,A肯定想找一条最长的路走,所以有下面几种情况:

如果两个以上的单调段,那么先手必然输,因为:

  1. 如果是全是一个方向的单调段,那么小\(A\)无论如何都会被小\(B\)堵截。
  2. 如果对于山峰段,即一个点左右分别为单调递增单调递减,有多个,那么\(B\)后手总能选到一个地方赢得比赛(画几个例子试试)。
  3. 如果对于山谷段,及一个点左右分别为单调递减单调递增,有多个,那么\(B\)后手也同样总能选到一个地方赢得比赛(画几个例子试试)。

如果就只有一个单调段,那么更不用说了,B只需要放在A旁边堵A即可,赢得比赛。

所以如果想要先手赢,那么必然是只要一个山峰段,同时山峰段还要左右恰好对称才可以,如果不对称那\(B\)也可以找一个地方拦截\(A\),或者走的路比更长,如果对称情况下,\(A\)必然选择连接点,而这时小\(B\)只能选两端点,这时如果\(A\)躲避\(B\)走另一边,那么它无论如何都输,因此他只能跟\(B\)对着走,而这时如果\(maxl % 2 == 0\),那么它依然输,所以只有\(maxl % 2 != 0\)情况下同时是对称的山峰段才赢,其余情况均输。

代码:

#include <iostream>
#include <cstring>
#include <algorithm>
#include <cstdio>
#include <vector>
#include <map>
#include <cstring> //#pragma GCC optimize(2)
//#pragma GCC optimize(3,"Ofast","inline") using namespace std; #define Inf 0x3f3f3f3f
#define PII pair<int, int>
#define P2LL pair<long long, long long>
#define endl '\n'
#define pub push_back
#define pob pop_back typedef long long LL;
typedef unsigned long long ULL;
typedef vector<long long> VLL;
typedef vector<int> VI; const int Mod = 1000000007; LL gcd(LL a, LL b) {
return b ? gcd(b, a % b) : a;
} const int N = 1E5 + 10;
int n, p[N];
int pre[N], suff[N]; void solve() {
scanf("%d", &n);
for (int i = 1; i <= n; i++) scanf("%d", &p[i]); for (int i = 1; i <= n; i++) {
if (p[i] > p[i - 1]) pre[i] = pre[i - 1] + 1;
else pre[i] = 1;
}
for (int i = n; i >= 1; i--) {
if (p[i] > p[i + 1]) suff[i] = suff[i + 1] + 1;
else suff[i] = 1;
} /* for (int i = 1; i <= n; i++) cout << pre[i] << " ";
cout << endl;
for (int i = 1; i <= n; i++) cout << suff[i] << " ";
cout << endl; */ int maxl = 0;
for (int i = 1; i <= n; i++) maxl = max({maxl, pre[i], suff[i]}); int cnt1 = 0, cnt2 = 0, idx1 = 0, idx2 = 0;
for (int i = 1; i <= n; i++) {
if (pre[i] == maxl) {
cnt1++;
idx1 = i;
}
if (suff[i] == maxl) {
cnt2++;
idx2 = i;
}
} if (cnt1 + cnt2 != 2) {
puts("0");
return;
} else if (cnt1 + cnt2 == 2 && idx1 == idx2) {
puts(maxl % 2 == 0 ? "0" : "1");
} else puts("0");
} int main()
{
//ios::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);
solve();
return 0;
}

Codeforces Round #706 (Div. 2) A-D题解的更多相关文章

  1. Codeforces Round #612 (Div. 2) 前四题题解

    这场比赛的出题人挺有意思,全部magic成了青色. 还有题目中的图片特别有趣. 晚上没打,开virtual contest打的,就会前三道,我太菜了. 最后看着题解补了第四道. 比赛传送门 A. An ...

  2. Codeforces Round #198 (Div. 2)A,B题解

    Codeforces Round #198 (Div. 2) 昨天看到奋斗群的群赛,好奇的去做了一下, 大概花了3个小时Ak,我大概可以退役了吧 那下面来稍微总结一下 A. The Wall Iahu ...

  3. Codeforces Round #672 (Div. 2) A - C1题解

    [Codeforces Round #672 (Div. 2) A - C1 ] 题目链接# A. Cubes Sorting 思路: " If Wheatley needs more th ...

  4. Codeforces Round #614 (Div. 2) A-E简要题解

    链接:https://codeforces.com/contest/1293 A. ConneR and the A.R.C. Markland-N 题意:略 思路:上下枚举1000次扫一遍,比较一下 ...

  5. Codeforces Round #610 (Div. 2) A-E简要题解

    contest链接: https://codeforces.com/contest/1282 A. Temporarily unavailable 题意: 给一个区间L,R通有网络,有个点x,在x+r ...

  6. Codeforces Round #611 (Div. 3) A-F简要题解

    contest链接:https://codeforces.com/contest/1283 A. Minutes Before the New Year 题意:给一个当前时间,输出离第二天差多少分钟 ...

  7. Codeforces Round #499 (Div. 2) D. Rocket题解

    题目: http://codeforces.com/contest/1011/problem/D This is an interactive problem. Natasha is going to ...

  8. Codeforces Round #499 (Div. 2) C Fly题解

    题目 http://codeforces.com/contest/1011/problem/C Natasha is going to fly on a rocket to Mars and retu ...

  9. Codeforces Round #198 (Div. 2)C,D题解

    接着是C,D的题解 C. Tourist Problem Iahub is a big fan of tourists. He wants to become a tourist himself, s ...

  10. Codeforces Round #579 (Div. 3) 套题 题解

    A. Circle of Students      题目:https://codeforces.com/contest/1203/problem/A 题意:一堆人坐成一个环,问能否按逆时针或者顺时针 ...

随机推荐

  1. 创建python虚拟环境并打包python文件

    前言 当需要为一个离线环境部署python应用时,离线环境可能缺少各种python环境,有docker的话可以用docker,没有docker可以用pyinstaller打包成二进制文件.pyinst ...

  2. SpringBoot3集成Quartz

    目录 一.简介 二.工程搭建 1.工程结构 2.依赖管理 3.数据库 4.配置文件 三.Quartz用法 1.初始化加载 2.新增任务 3.更新任务 4.暂停任务 5.恢复任务 6.执行一次 7.删除 ...

  3. [glibc2.23源码]阅读源码&调试,找出free_hook-0x13分配失败的原因

    0x00 写在前面 发freebuf了:https://www.freebuf.com/articles/endpoint/373258.html 本次阅读源码是本人第一次,算是一个全新的开始.本次看 ...

  4. 如何找到docker容器中的网卡外联的veth pair的另一张网卡

    1.概述 在Docker容器中,每个容器都有一个或多个网络接口(网卡),用于连接容器内部与宿主机或其他容器进行通信.这些网络接口中的一些可能是veth pair,也就是虚拟以太网对,它们以成对的方式存 ...

  5. 【pandas小技巧】--花哨的DataFrame

    最近github上发现了一个库(plottable),可以用简单的方式就设置出花哨的 DataFrame 样式. github上的地址:https://github.com/znstrider/plo ...

  6. ATtiny88初体验(六):SPI

    ATtiny88初体验(六):SPI SPI介绍 ATtiny88自带SPI模块,可以实现数据的全双工三线同步传输.它支持主从两种模式,可以配置为LSB或者MSB优先传输,有7种可编程速率,支持从空闲 ...

  7. 安卓APK签名注入大师(APP注入弹窗,注入打开密码,注入过期时间, 注入提示信息,一机一码)

    安卓APK签名注入大师可以给安卓APK文件一键注入APP注入弹窗,注入打开密码,注入过期时间, 注入提示信息,一机一码等功能,方便开发人员给自己的APK文件添加消息提示, 密码等功能. 可以保护文件安 ...

  8. 【规范】SpringBoot接口返回结果及异常统一处理,这样封装才优雅

    前言 缘由 博友的需求就是我最大的动力 博友一说话,本狗笑哈哈.博友要我写啥,我就写啥. 特来一篇关于SpringBoot接口返回结果及异常统一处理,虽说封不封装都能用,但咱后端也得给前端小姐姐留个好 ...

  9. vue3探索——pinia高阶使用

    以下是一些 Pinia 的其他高阶功能: storeToRefs():响应式解构仓库,保证解构出来的数据是响应式的数据. 状态持久化:Pinia 并没有内置的状态持久化功能,但你可以使用第三方库或自定 ...

  10. Llama2-Chinese项目:2.1-Atom-7B预训练

      虽然Llama2的预训练数据相对于第一代LLaMA扩大了一倍,但是中文预训练数据的比例依然非常少,仅占0.13%,这也导致了原始Llama2的中文能力较弱.为了能够提升模型的中文能力,可以采用微调 ...