CF1537A Arithmetic Array

洛谷传送门

CF1537A


分析

用这 \(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

洛谷传送门

CF1537B


分析

要想使三点曼哈顿距离最大,把另外两点放在对角即可


代码

#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

洛谷传送门

CF1537C


分析

首先第一个数和最后一个数可以先确定下来。

如果把剩下的数直接在中间升序排列,下界为 \(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

洛谷传送门

CF1537D


分析

考虑一个奇数减去一个因子,会变成偶数,然后其又会变成奇数。

最后变为质数或 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)

洛谷传送门

CF1537E2


分析

答案肯定是一段前缀重复好多次的结果,设当前选中的前缀长度为 \(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

洛谷传送门

CF1537F


代码(分析在上篇题解中)

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

  1. Codeforces Round #726 (Div.2) A-E1 题解

    A. Arithmetic Array 题目大意:一串数,求添加多少个非负整数后平均值为1 代码: //CF726A #include<bits/stdc++.h> using names ...

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

  3. Codeforces Round #354 (Div. 2) ABCD

    Codeforces Round #354 (Div. 2) Problems     # Name     A Nicholas and Permutation standard input/out ...

  4. Codeforces Round #368 (Div. 2)

    直达–>Codeforces Round #368 (Div. 2) A Brain’s Photos 给你一个NxM的矩阵,一个字母代表一种颜色,如果有”C”,”M”,”Y”三种中任意一种就输 ...

  5. cf之路,1,Codeforces Round #345 (Div. 2)

     cf之路,1,Codeforces Round #345 (Div. 2) ps:昨天第一次参加cf比赛,比赛之前为了熟悉下cf比赛题目的难度.所以做了round#345连试试水的深浅.....   ...

  6. Codeforces Round #279 (Div. 2) ABCDE

    Codeforces Round #279 (Div. 2) 做得我都变绿了! Problems     # Name     A Team Olympiad standard input/outpu ...

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

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

  9. Codeforces Round #371 (Div. 1)

    A: 题目大意: 在一个multiset中要求支持3种操作: 1.增加一个数 2.删去一个数 3.给出一个01序列,问multiset中有多少这样的数,把它的十进制表示中的奇数改成1,偶数改成0后和给 ...

  10. Codeforces Round #268 (Div. 2) ABCD

    CF469 Codeforces Round #268 (Div. 2) http://codeforces.com/contest/469 开学了,时间少,水题就不写题解了,不水的题也不写这么详细了 ...

随机推荐

  1. [Android 逆向]Xposed 破解 切水果大战原版.apk

    代码 public class Main implements IXposedHookLoadPackage { boolean flag = false; @Override public void ...

  2. 项目实战:Qt+OpenCV图像处理与识别算法平台

    若该文为原创文章,未经允许不得转载原博主博客地址:https://blog.csdn.net/qq21497936原博主博客导航:https://blog.csdn.net/qq21497936/ar ...

  3. ASP.NET XML序列化

    整理一下ASP.NET里面如何序列化实体为XML,获取解析XML内容为实体. 第一步要添加程序集引用,项目-->引用-->鼠标右键-->添加引用-->选择程序集-->Sy ...

  4. 【LeetCode数组#4滑动窗口】长度最小的子数组+子数组最大平均数I

    长度最小的子数组 力扣题目链接(opens new window) 给定一个含有 n 个正整数的数组和一个正整数 s ,找出该数组中满足其和 ≥ s 的长度最小的 连续 子数组,并返回其长度.如果不存 ...

  5. 如何在矩池云上安装语音识别模型 Whisper

    如何在矩池云上安装语音识别模型 Whisper Whisper 是 OpenAI 近期开源的一个语音识别的模型,研究人员基于 680,000 小时的标记音频数据进行训练,它同时也是一个多任务模型,可以 ...

  6. HTTP1.0/HTTP1.1/HTTP2.0的演进

    HTTP1.0 短连接,每次请求都需要重新建立连接 不支持断点续传 HTTP1.1 支持长连接,同一个客户端连接可保持长连接,请求可在连接中顺序发出. 查看http请求头中有keepalive 参数 ...

  7. STM32SPIFLASH读写

    STM32SPIFLASH读写 1.1 SPI注意事项 SPI是同步通信,即通信双方每次信息交互必会带有一问一答,这代表在正常的单核MCU(例如STM32)中很难实现软件模拟的双向SPI通信(TFT屏 ...

  8. 在anaconda中为jupyter安装代码自动补全或代码自动提示功能,jupyter nbextensions不显示拓展,另附格式化代码插件的安装方法

    操作步骤 进入命令行环境.我使用的是conda.有两种方式进入命令行. 方法1:通过anconda navigator界面,选择environments,选择对应环境名,选择open terminal ...

  9. Redis单线程为什么如此之快

    一.概述 Redis的高并发和快简单可以归结为一下几点: 1.Redis是基于内存的: 2.Redis是单线程的: 3.Redis使用多路复用技术. 4.高效的数据结构 但具体怎么做的呢,下面来详细看 ...

  10. sed 资源

    sed教程 菜鸟教程正则 MDN正则 正则测试工具 文本替换 s sed有多种分割符,比如你要替换路径字符串时,使用反斜杠很难看,则可以用 : 或者 _ 或者 | 这三个符号都可作为分隔符. & ...