【CF VP记录】Codeforces Round 1008 (Div. 2)
比赛链接
本文原文发布于博客园,如您在其他平台刷到此文,请前往博客园获得更好的阅读体验。
跳转链接:https://www.cnblogs.com/TianTianChaoFangDe/p/18766146
开题 + 补题情况
坠机场,要是赛时打了的话就又回青了,前两题很快开出来了,第三题脑残了,一开始觉得只需要构造第一个数就行了然后爽吃两发罚时。

A. Final Verdict
瞎猜的,只要所有数的和除以 \(n\) 得到的值为 \(x\) 一定有解,暂时没想到如何证明,有空再来证一证。
点击查看代码
#include <bits/stdc++.h>
#define inf 2e18
#define int long long
const int N = 2e5 + 9;
void solve()
{
int n, x;std::cin >> n >> x;
std::vector<int> a(n);
int sum = 0;
for(auto &i : a) {
std::cin >> i;
sum += i;
}
if(sum % n == 0 && sum / n == x) {
std::cout << "YES\n";
} else {
std::cout << "NO\n";
}
}
B. Vicious Labyrinth
题目要让所有人离 \(n\) 的距离最小化。
我们对 \(k\) 分奇偶讨论:
- 如果 \(k\) 为奇数,那么我们只需要把 \(n\) 传送到 \(n - 1\),其余位置传送到 \(n\),那么经过一次传送后,就只有一个人在 \(n - 1\) 的位置,其他人均在 \(n\) 的位置,接下来偶数次只会在这两个位置反复横跳,答案为 \(1\)。
- 如果 \(k\) 为偶数,那么我们把 \(n - 1\) 传送到 \(n\),其余位置传送到 \(n - 1\),这样再来一次传送后,就只有一个人在 \(n - 1\) 的位置,其他人均在 \(n\) 的位置,接下来偶数次只会在这两个位置反复横跳,答案为 \(1\)。
由于不能往原位置传送,所以至少有一个人无法抵达 \(n\),因此答案至少为 \(1\),所以上述构造为最优解。
点击查看代码
#include <bits/stdc++.h>
#define inf 2e18
#define int long long
const int N = 2e5 + 9;
void solve()
{
int n, k;std::cin >> n >> k;
if(k & 1) {
for(int i = 1;i <= n;i ++) {
if(i == n)std::cout << n - 1 << ' ';
else std::cout << n << ' ';
}
} else {
for(int i = 1;i <= n;i ++) {
if(i == n - 1)std::cout << n << ' ';
else std::cout << n - 1 << ' ';
}
}
std::cout << '\n';
}
C. Breach of Faith
一开始以为只要把第一项当成未知项,然后把后面的数排一下序求一下就行了,直到我搓出了这个样例 \(2, 3, 4, 5\),这个样例按这个想法来的话,求出来的值是 \(-2\),显然不符合题意,并且除了这种情况,还有可能导致数字重复,同样不符合题意。
对于此题,我们对题目中的式子进行变形:\(0 = -a_1 + a_2 -a_3 + ... +a_{2 \times n} - a_{2 \times n + 1}\)。
我们首先对所给 \(b\) 数组进行一下从小到大排序,因为这样可以一减一加后是正数,更容易命中答案(其实这个也是猜的,为什么要排序具体的也没细证)。
然后,我们对上面那个式子枚举每一项作为消失项,通过对上面的新式子进行移项求出这一项的值,然后判断一下这个值是否合法,如果合法,这就是满足题意的构造。
对于移项后其他项的和,可以通过记录奇偶前缀和来快速求出。
时间复杂度:\(O(n \log n)\),\(\log n\) 来源于我使用了 map 记录一个数字是否出现过。
点击查看代码
#include <bits/stdc++.h>
#define inf 2e18
#define int long long
const int N = 2e5 + 9;
void solve()
{
int n;std::cin >> n;
std::vector<int> a(2 * n + 2), b(2 * n + 1);
std::map<int, bool> vis;
for(int i = 1;i <= 2 * n;i ++) {
std::cin >> b[i];
vis[b[i]] = true;
}
sort(b.begin() + 1, b.end());
std::vector<int> preodd(2 * n + 2, 0), preeve(2 * n + 2, 0);
for(int i = 1;i <= 2 * n;i ++) {
if(i & 1) {
preodd[i] = preodd[i - 1] + b[i];
preeve[i] = preeve[i - 1];
}
else {
preodd[i] = preodd[i - 1];
preeve[i] = preeve[i - 1] + b[i];
}
}
for(int i = 1;i <= 2 * n + 1;i ++) {
int ans = 0;
ans += preodd[i - 1];
ans -= preeve[i - 1];
ans += preeve[2 * n] - preeve[i - 1];
ans -= preodd[2 * n] - preodd[i - 1];
if(i & 1) {
ans = -ans;
}
if(!vis.count(ans) && ans > 0) {
for(int j = 1;j < i;j ++) {
a[j] = b[j];
}
a[i] = ans;
for(int j = i;j <= 2 * n;j ++) {
a[j + 1] = b[j];
}
break;
}
}
for(int i = 1;i <= 2 * n + 1;i ++) {
std::cout << a[i] << " ";
}
std::cout << '\n';
}
【CF VP记录】Codeforces Round 1008 (Div. 2)的更多相关文章
- 【cf比赛记录】Codeforces Round #601 (Div. 2)
Codeforces Round #601 (Div. 2) ---- 比赛传送门 周二晚因为身体不适鸽了,补题补题 A // http://codeforces.com/contest/1255/p ...
- 【cf比赛记录】Codeforces Round #600 (Div. 2)
Codeforces Round #600 (Div. 2) ---- 比赛传送门 昨晚成绩还好,AC A,B题,还能上分(到底有多菜) 补了C.D题,因为昨晚对C.D题已经有想法了,所以补起题来也快 ...
- cf之路,1,Codeforces Round #345 (Div. 2)
cf之路,1,Codeforces Round #345 (Div. 2) ps:昨天第一次参加cf比赛,比赛之前为了熟悉下cf比赛题目的难度.所以做了round#345连试试水的深浅..... ...
- 刷题记录:Codeforces Round #734 (Div. 3)
Codeforces Round #734 (Div. 3) 20210920.网址:https://codeforces.com/contest/1551. 编程细节:下标定义不要一会[1,n]一会 ...
- 刷题记录:Codeforces Round #739 (Div. 3)
Codeforces Round #739 (Div. 3) 20210907.网址:https://codeforces.com/contest/1560. --(叹). A 不希望出现带" ...
- 刷题记录:Codeforces Round #724 (Div. 2)
Codeforces Round #724 (Div. 2) 20210713.网址:https://codeforces.com/contest/1536. div2明显比div3难多了啊-只做了前 ...
- 刷题记录:Codeforces Round #725 (Div. 3)
Codeforces Round #725 (Div. 3) 20210704.网址:https://codeforces.com/contest/1538. 感觉这个比上一个要难. A 有一个n个数 ...
- 刷题记录:Codeforces Round #719 (Div. 3)
Codeforces Round #719 (Div. 3) 20210703.网址:https://codeforces.com/contest/1520. 没错,我是个做div3的蒟蒻-- A 大 ...
- Codeforces Round #803 (Div. 2) A-D 刚vp完还没补题
Codeforces Round #803 (Div. 2) 2022/7/24 上午VP 传送门:https://codeforces.com/contest/1698 A. XOR Mixup 随 ...
- 刷题记录:Codeforces Round #731 (Div. 3)
Codeforces Round #731 (Div. 3) 20210803.网址:https://codeforces.com/contest/1547. 感觉这次犯的低级错误有亿点多-- A 一 ...
随机推荐
- 【转载】基于timestamp和nonce的防重放攻击
https://www.cnblogs.com/mymelody/p/7325325.html 以前总是通过timestamp来防止重放攻击,但是这样并不能保证每次请求都是一次性的.今天看到了一篇 ...
- 【转载】Spring Cloud Gateway排错、调试技巧总结
http://www.imooc.com/article/290824 本文总结Spring Cloud Gateway的排错.调试技巧.欢迎留言补充! 第一式:Actuator监控端点 借助Actu ...
- Sqlsugar 跨库查询小心得(同服务器不同数据库)
同一个服务器下的不同数据库,目前还没有进行跨服务器的查询,以后有待研究-- 1.使用的是Left Join左查询,因此连接字符串应该是写的第一个表所在的数据库的连接字符串 假设数据库A,B,连接字符串 ...
- SHA256 64 位加密
/// <summary> /// SHA256 64位加密 /// </summary> /// <param name="input">&l ...
- AndroidStudio 彻底关闭http网络代理方法
以前在AndroidStudio中设置完代理后,会在项目的gradle.properties文件中生成代理配置信息: 即使你在setting的http proxy中关掉代理,实际编译时还会使用上次设置 ...
- IM开发者的零基础通信技术入门(十三):为什么手机信号差?一文即懂!
[来源申明]本文引用了微信公众号"网优雇佣军"的<是谁偷走了我家的手机信号?>文章内容.为了更好的内容呈现,下文在引用和收录时内容有改动,转载时请注明原文来源信息,尊重 ...
- TagHelper中获取当前Url
在自定义TagHelper时,我们无法通过TagHelperContext 和 TagHelperOutput 获取到当前路由的信息,我们需要添加注入ViewContext [HtmlAttribut ...
- 记录以下uniapp写小程序然后进行图片上传压缩
今天记录一下uniapp写小程序上传图片压缩的功能 首先定义上传图片的方法 然后res.tempFilePath[0]就是图片的临时路径 其次定义压缩图片然后获取压缩后图片大小的方法,方法使用canv ...
- Solution Set -「AGC 007~009」C~F
目录 「AGC 007C」Pushing Balls 「AGC 007D」Shik and Game 「AGC 007E」Shik and Travel ^ 「AGC 007F」Shik and Co ...
- c# 获取用户桌面选择的文件
引用COM组件 Shell32 Shell32.ShellFolderView desktopFolderView; int hwnd; Shell32.Shell iShell = new Shel ...