Codeforces Round #726 (Div. 2)
CF1537A Arithmetic Array
分析
用这 \(n\) 个数的总和 \(sum\) 判断:
如果 \(sum<n\) 直接用 \(n-sum+1\) 补上即可
如果 \(sum>n\) 意味着要用 \(sum-n\) 个 0 补上
代码
#include <cstdio>
#include <cctype>
using namespace std;
int iut(){
int ans=0,f=1; char c=getchar();
while (!isdigit(c)) f=(c=='-')?-f:f,c=getchar();
while (isdigit(c)) ans=ans*10+c-48,c=getchar();
return ans*f;
}
void print(int ans){
if (ans>9) print(ans/10);
putchar(ans%10+48);
}
int main(){
for (int T=iut();T;--T){
int n=iut(),sum=0;
for (int i=1;i<=n;++i) sum+=iut();
print(sum>=n?(sum-n):1),putchar(10);
}
return 0;
}
CF1537B Bad Boy
分析
要想使三点曼哈顿距离最大,把另外两点放在对角即可
代码
#include <cstdio>
#include <cctype>
using namespace std;
int iut(){
int ans=0,f=1; char c=getchar();
while (!isdigit(c)) f=(c=='-')?-f:f,c=getchar();
while (isdigit(c)) ans=ans*10+c-48,c=getchar();
return ans*f;
}
int main(){
for (int T=iut();T;--T){
int n=iut(),m=iut(); iut(),iut();
printf("1 1 %d %d\n",n,m);
}
return 0;
}
CF1537C Challenging Cliffs
分析
首先第一个数和最后一个数可以先确定下来。
如果把剩下的数直接在中间升序排列,下界为 \(n-3\)
其浪费了第一个数和最后一个数所相邻的位置。
那么如果以 \((pos,n]\) 和 \([1,pos]\) 排列,就可以达到 \(n-2\) 的下界
代码
#include <cstdio>
#include <cctype>
#include <algorithm>
using namespace std;
int n,a[200011];
int iut(){
int ans=0,f=1; char c=getchar();
while (!isdigit(c)) f=(c=='-')?-f:f,c=getchar();
while (isdigit(c)) ans=ans*10+c-48,c=getchar();
return ans*f;
}
int main(){
for (int T=iut();T;--T){
n=iut();
for (int i=1;i<=n;++i) a[i]=iut();
sort(a+1,a+1+n);
if (n==2) printf("%d %d\n",a[1],a[2]);
else{
int pos=1;
for (int i=2;i<n;++i)
if (a[i+1]-a[i]<a[pos+1]-a[pos]) pos=i;
for (int i=pos+1;i<=n;++i) printf("%d ",a[i]);
for (int i=1;i<=pos;++i) printf("%d%c",a[i],i==pos?10:32);
}
}
return 0;
}
CF1537D Deleting Divisors
分析
考虑一个奇数减去一个因子,会变成偶数,然后其又会变成奇数。
最后变为质数或 1 时终止,发现奇数时后手必胜。
同时含有奇质因子的偶数一定先手必胜。
剩下 2 的幂次方通过指数的奇偶性判断是否先手必胜。
代码
#include <cstdio>
#include <cctype>
using namespace std;
int n,c;
int iut(){
int ans=0,f=1; char c=getchar();
while (!isdigit(c)) f=(c=='-')?-f:f,c=getchar();
while (isdigit(c)) ans=ans*10+c-48,c=getchar();
return ans*f;
}
int main(){
for (int T=iut();T;--T){
n=iut(),c=0;
if (n&1) {puts("Bob"); continue;}
while (!(n&1)) n>>=1,++c;
if (n>1) puts("Alice");
else puts(c&1?"Bob":"Alice");
}
return 0;
}
CF1537E2 Erase and Extend (Hard Version)
分析
答案肯定是一段前缀重复好多次的结果,设当前选中的前缀长度为 \(ans\),
枚举新的前缀长度 \(i\),判断末位大小,如果 \(s[i-1]<s[(i-1)%ans]\) ,
直接将 \(i\) 作为新的 \(ans\),如果大于直接退出即可
代码
#include <cstdio>
#include <cstring>
using namespace std;
int n,m,ans; char s[500011];
int main(){
scanf("%d%d%s",&n,&m,s),ans=1;
for (int i=1;i<n;++i)
if (s[i]>s[i%ans]) break;
else if (s[i]<s[i%ans]) ans=i+1;
for (int i=0;i<m;++i) putchar(s[i%ans]);
return 0;
}
CF1537F Figure Fixing
代码(分析在上篇题解中)
#include <cstdio>
#include <cctype>
using namespace std;
const int N=200011; long long s[2];
struct node{int y,next;}e[N<<1];
int v[N],a[N],n,m,flag,et,as[N];
int iut(){
int ans=0,f=1; char c=getchar();
while (!isdigit(c)) f=(c=='-')?-f:f,c=getchar();
while (isdigit(c)) ans=ans*10+c-48,c=getchar();
return ans*f;
}
bool dfs(int x){
bool flag=1; s[v[x]]+=a[x];
for (int i=as[x];i;i=e[i].next)
if (v[e[i].y]==v[x]) flag=0;
else if (v[e[i].y]==-1) v[e[i].y]=v[x]^1,flag&=dfs(e[i].y);
return flag;
}
int main(){
for (int T=iut();T;--T){
n=iut(),m=iut(),flag=et=1;
for (int i=1;i<=n;++i) a[i]=iut(),v[i]=-1;
for (int i=1;i<=n;++i) a[i]=iut()-a[i];
for (int i=1;i<=m;++i){
int x=iut(),y=iut();
e[++et]=(node){y,as[x]},as[x]=et;
e[++et]=(node){x,as[y]},as[y]=et;
}
for (int i=1;i<=n;++i)
if (v[i]==-1){
v[i]=s[0]=s[1]=0;
bool now=dfs(i);
if (now&&(s[0]!=s[1])) {puts("NO"),flag=0; break;}
if (!now&&((s[0]^s[1])&1)) {puts("NO"),flag=0; break;}
}
for (int i=1;i<=n;++i) as[i]=0;
if (flag) puts("YES");
}
return 0;
}
Codeforces Round #726 (Div. 2)的更多相关文章
- Codeforces Round #726 (Div.2) A-E1 题解
A. Arithmetic Array 题目大意:一串数,求添加多少个非负整数后平均值为1 代码: //CF726A #include<bits/stdc++.h> using names ...
- Codeforces Round #366 (Div. 2) ABC
Codeforces Round #366 (Div. 2) A I hate that I love that I hate it水题 #I hate that I love that I hate ...
- Codeforces Round #354 (Div. 2) ABCD
Codeforces Round #354 (Div. 2) Problems # Name A Nicholas and Permutation standard input/out ...
- Codeforces Round #368 (Div. 2)
直达–>Codeforces Round #368 (Div. 2) A Brain’s Photos 给你一个NxM的矩阵,一个字母代表一种颜色,如果有”C”,”M”,”Y”三种中任意一种就输 ...
- cf之路,1,Codeforces Round #345 (Div. 2)
cf之路,1,Codeforces Round #345 (Div. 2) ps:昨天第一次参加cf比赛,比赛之前为了熟悉下cf比赛题目的难度.所以做了round#345连试试水的深浅..... ...
- Codeforces Round #279 (Div. 2) ABCDE
Codeforces Round #279 (Div. 2) 做得我都变绿了! Problems # Name A Team Olympiad standard input/outpu ...
- Codeforces Round #262 (Div. 2) 1003
Codeforces Round #262 (Div. 2) 1003 C. Present time limit per test 2 seconds memory limit per test 2 ...
- Codeforces Round #262 (Div. 2) 1004
Codeforces Round #262 (Div. 2) 1004 D. Little Victor and Set time limit per test 1 second memory lim ...
- Codeforces Round #371 (Div. 1)
A: 题目大意: 在一个multiset中要求支持3种操作: 1.增加一个数 2.删去一个数 3.给出一个01序列,问multiset中有多少这样的数,把它的十进制表示中的奇数改成1,偶数改成0后和给 ...
- Codeforces Round #268 (Div. 2) ABCD
CF469 Codeforces Round #268 (Div. 2) http://codeforces.com/contest/469 开学了,时间少,水题就不写题解了,不水的题也不写这么详细了 ...
随机推荐
- 2024-02-24:用go语言,给你一个 n 个点的带权无向连通图,节点编号为 0 到 n-1, 同时还有一个数组 edges ,其中 edges[i] = [fromi, toi, weighti
2024-02-24:用go语言,给你一个 n 个点的带权无向连通图,节点编号为 0 到 n-1, 同时还有一个数组 edges ,其中 edges[i] = [fromi, toi, weighti ...
- less变量书写及样式混入
定义变量 定义混入样式 变量及混入样式使用 样式文件中 ~@代表src
- RK3568开发笔记(二):入手RK3568开发板的套件介绍、底板介绍和外设测试
前言 本篇主要介绍RK3568芯片和入手开发板的底板介绍以及开发板的外设. 开发板 笔者的开发板是全套+10.1寸屏. 开发板实物 开发板资源 开发版本提供资料 开发 ...
- vue运行时报错Error from chokidar
原文博客地址 Error from chokidar (/home/youyou/文档/vue/vuetask01/node_modules/lodash): Error: ENOSPC: Syste ...
- 如何在C#中解析Excel公式
前言 在日常工作中,我们经常需要在Excel中使用公式对表中数据进行计算(求和.求差和求均值等)和分析,从而实现对数据的分类,通常情况下,当数据量较少或场景变化单一的情况下,使用公式可以满足用户的要求 ...
- Android 安装手机程序有问题/点击runAPP 程序安装不了手机
可以在 gradle.properties 里添加 android.injected.testOnly=false 点击同步 就可以运行了 如下:
- 深入解析ASP.NET Core MVC的模块化设计[下篇]
ASP.NET Core MVC的"模块化"设计使我们可以构成应用的基本单元Controller定义在任意的模块(程序集)中,并在运行时动态加载和卸载.<设计篇>介绍了 ...
- Educational Codeforces Round 65 (Rated for Div. 2)C. News Distribution(模拟,计算的时候去重)
这道题目明显和出现4次的数和出现2次的数的个数有关系,只需要在每次更新之后维护这两个信息即可,我们在算出现2次的数的个数时其实会把出现4次的数的个数会把出现2次的数的个数+2,在判断时需要考虑这一点. ...
- hutool,真香!
前言 今天给大家介绍一个能够帮助大家提升开发效率的开源工具包:hutool. Hutool是一个小而全的Java工具类库,通过静态方法封装,降低相关API的学习成本,提高工作效率,使Java拥有函数式 ...
- KTL 一个支持C++14编辑公式的K线技术工具平台
K,K线,Candle蜡烛图. T,技术分析,工具平台 L,公式Language语言使用c++14,Lite小巧简易. 项目仓库:https://github.com/bbqz007/KTL 国内仓库 ...