Codeforces Round #803 (Div. 2)

2022/7/24 上午VP

传送门https://codeforces.com/contest/1698

A. XOR Mixup

随便输出数组里的一个数字就行

#include<bits/stdc++.h>
signed main(){
std::ios::sync_with_stdio(false);
int t;std::cin>>t;
while(t--){
int n;std::cin>>n;
int in;
for(int i=1;i<=n;i++){
std::cin>>in;
}
std::cout<<in<<"\n";
}
}

B. Rising Sand

k大于1的时候,不管怎么搞,最终答案都不会变化的。因为对任意i增高x,他的两个邻居也最少增加x。所以直接统计出原数组的答案就行。

k=1的话就不管原数组如何了,答案直接拉满就行。

#include<bits/stdc++.h>
const int N =2e5+10;
#define int long long
int a[N];
signed main(){
std::ios::sync_with_stdio(false);
int t;std::cin>>t;
while(t--){
int n,k;std::cin>>n>>k;
for(int i=1;i<=n;i++)std::cin>>a[i];
if(k==1){
std::cout<<(n-1)/2<<"\n";
continue;
}
int ans=0;
for(int i=2;i<n;i++)if(a[i]>a[i-1]+a[i+1])ans++;
std::cout<<ans<<"\n";
}
}

C. 3SUM Closure

题意:数组中任选3个数,要求三个数的和在数组里存在。问成不成立。

:如果有超过2个的负数或正数,那么他们3个加起来就能变成更大的数字一发不可收拾。所以直接排除。

于是就限制在2个以内了。然后分类讨论就好。

#include<bits/stdc++.h>
const int N =2e5+10;
#define int long long
int a[N];
std::vector<int>ve[2];
signed main(){
std::ios::sync_with_stdio(false);
int t;std::cin>>t;
while(t--){
int n;std::cin>>n;
for(int i=1;i<=n;i++)std::cin>>a[i];
bool f=1;
ve[0].clear();ve[1].clear();
for(int i=1;i<=n;i++){
if(a[i])ve[(a[i]>0)].push_back(a[i]);
}
std::sort(ve[0].begin(),ve[0].end());
std::sort(ve[1].begin(),ve[1].end());
if(ve[0].size()>2||ve[1].size()>2)f=0;
if(ve[0].size()==2||ve[1].size()==2){
if(ve[0].size()+ve[1].size()!=n)f=0;
}
if(ve[0].size()==2&&ve[1].size()==2){
if(n!=4)f=0;
if(ve[0][0]+ve[1][1]!=0||ve[0][1]+ve[1][0]!=0){
bool ff=0;
if(ve[0][1]==ve[0][0]){
if(ve[1][0]+3*ve[0][0]==0||ve[1][1]+3*ve[0][0]==0){
if(ve[1][0]+2*ve[0][0]==ve[1][1]||ve[1][1]+2*ve[0][0]==ve[1][0])ff=1;
}
}
std::swap(ve[0],ve[1]);
if(ve[0][1]==ve[0][0]){
if(ve[1][0]+3*ve[0][0]==0||ve[1][1]+3*ve[0][0]==0){
if(ve[1][0]+2*ve[0][0]==ve[1][1]||ve[1][1]+2*ve[0][0]==ve[1][0])ff=1;
}
}
if(!ff)f=0;
}
}
if(ve[0].size()==1&&ve[1].size()==1){
if(ve[0][0]+ve[1][0]!=0)f=0;
}
if(ve[0].size()==0||ve[1].size()==0){
if(ve[0].size()==2||ve[1].size()==2)f=0;
}
if(ve[0].size()==2||ve[1].size()==2){
if(ve[0].size()==1||ve[1].size()==1){
if(n!=3)f=0;
if(ve[0].size()==1){
if(ve[0][0]+ve[1][0]!=0&&vc++e[0][0]+ve[1][1]!=0)f=0;
}
if(ve[1].size()==1){
if(ve[1][0]+ve[0][0]!=0&&ve[1][0]+ve[0][1]!=0)f=0;
}
}
}
if(f)std::cout<<"YES\n";
else std::cout<<"NO\n";
}
}

D. Fixed Point Guessing

交互题二分

题意:有一个排列1,2,3,4。。。n。n为奇数。经过n/2次操作,每次操作选一对数字交换位置,换过的不能再换,那么最后一定有一个数字没被交换过。现在有15次询问机会,找到那个数字。

每次询问一个区间,回答区间的所有数字的升序。

解法:区间内交换的话一定是两两成对的,那么直接统计交换前后都属于这个区间的数字的数量,判断奇偶,就能直接知道区间是否含有答案。

于是可以二分查出答案,因为n最大才1e3所以只需要10次左右询问就能得出答案。

#include<bits/stdc++.h>
const int N =2e5+10;
#define int long long
int a[N];
std::vector<int>ve[2];
signed main(){
std::ios::sync_with_stdio(false);
int t;std::cin>>t;
while(t--){
int n;std::cin>>n;
for(int i=1;i<=n;i++)std::cin>>a[i];
bool f=1;
ve[0].clear();ve[1].clear();
for(int i=1;i<=n;i++){
if(a[i])ve[(a[i]>0)].push_back(a[i]);
}
std::sort(ve[0].begin(),ve[0].end());
std::sort(ve[1].begin(),ve[1].end());
if(ve[0].size()>2||ve[1].size()>2)f=0;
if(ve[0].size()==2||ve[1].size()==2){
if(ve[0].size()+ve[1].size()!=n)f=0;
}
if(ve[0].size()==2&&ve[1].size()==2){
if(n!=4)f=0;
if(ve[0][0]+ve[1][1]!=0||ve[0][1]+ve[1][0]!=0){
bool ff=0;
if(ve[0][1]==ve[0][0]){
if(ve[1][0]+3*ve[0][0]==0||ve[1][1]+3*ve[0][0]==0){
if(ve[1][0]+2*ve[0][0]==ve[1][1]||ve[1][1]+2*ve[0][0]==ve[1][0])ff=1;
}
}
std::swap(ve[0],ve[1]);
if(ve[0][1]==ve[0][0]){
if(ve[1][0]+3*ve[0][0]==0||ve[1][1]+3*ve[0][0]==0){
if(ve[1][0]+2*ve[0][0]==ve[1][1]||ve[1][1]+2*ve[0][0]==ve[1][0])ff=1;
}
}
if(!ff)f=0;
}
}
if(ve[0].size()==1&&ve[1].size()==1){
if(ve[0][0]+ve[1][0]!=0)f=0;
}
if(ve[0].size()==0||ve[1].size()==0){
if(ve[0].size()==2||ve[1].size()==2)f=0;
}
if(ve[0].size()==2||ve[1].size()==2){
if(ve[0].size()==1||ve[1].size()==1){
if(n!=3)f=0;
if(ve[0].size()==1){
if(ve[0][0]+ve[1][0]!=0&&ve[0][0]+ve[1][1]!=0)f=0;
}
if(ve[1].size()==1){
if(ve[1][0]+ve[0][0]!=0&&ve[1][0]+ve[0][1]!=0)f=0;
}
}
}
if(f)std::cout<<"YES\n";
else std::cout<<"NO\n";
}
}

E. PermutationForces II

咕咕咕


Codeforces Round #803 (Div. 2) A-D 刚vp完还没补题的更多相关文章

  1. Codeforces Round #267 (Div. 2) C. George and Job(DP)补题

    Codeforces Round #267 (Div. 2) C. George and Job题目链接请点击~ The new ITone 6 has been released recently ...

  2. Codeforces Round #310 (Div. 2) A. Case of the Zeros and Ones 水题

    A. Case of the Zeros and Ones Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/con ...

  3. Codeforces Round #430 (Div. 2) 【A、B、C、D题】

    [感谢牛老板对D题的指点OTZ] codeforces 842 A. Kirill And The Game[暴力] 给定a的范围[l,r],b的范围[x,y],问是否存在a/b等于k.直接暴力判断即 ...

  4. Codeforces Round #424 (Div. 2, rated, based on VK Cup Finals)A B题

    当时晚上打CF时候比较晚,加上是集训期间的室友都没有晚上刷题的习惯,感觉这场CF很不在状态.A题写复杂WA了一发后去厕所洗了个脸冷静了下,换个简单写法,可是用cin加了ios::sync_with_s ...

  5. Codeforces Round #554 (Div. 2) B. Neko Performs Cat Furrier Transform(思维题+log2求解二进制位数的小技巧)

    传送门 题意: 给出一个数x,有两个操作: ①:x ^= 2k-1; ②:x++; 每次操作都是从①开始,紧接着是② ①②操作循环进行,问经过多少步操作后,x可以变为2p-1的格式? 最多操作40次, ...

  6. Codeforces Round #294 (Div. 2)C - A and B and Team Training 水题

    C. A and B and Team Training time limit per test 1 second memory limit per test 256 megabytes input ...

  7. Codeforces Round #294 (Div. 2)B - A and B and Compilation Errors 水题

    B. A and B and Compilation Errors time limit per test 2 seconds memory limit per test 256 megabytes ...

  8. Codeforces Round #599 (Div. 2) A,B1,B2,C 【待补 D】

    排序+暴力 #include<bits/stdc++.h> using namespace std; #define int long long #define N 1005000 int ...

  9. Codeforces Round #598 (Div. 3) A,B,C,D{E,F待补}

    A. Payment Without Change   #include<bits/stdc++.h> using namespace std; #define int long long ...

  10. Codeforces Round #624 (Div. 3) A. Add Odd or Subtract Even(水题)

    You are given two positive integers aa and bb . In one move, you can change aa in the following way: ...

随机推荐

  1. android HttpURLConnection ,HttpClient设置Cookie

    上一阶段项目设计使用cookie信息实现登录访问功能,在实现过程遇到一些问题,下面整理一下: 首先,client想使用cookie,必须访问一次server从会话中获取cookie信息,然后在设置回去 ...

  2. RNN,LSTM,BERT

    目录 RNN LSTM 计算公式 参数量计算 self-attention bert 论文 源码 问题 问题:bert中进行ner为什么没有使用crf:使用DL进行序列标注问题的时候CRF是必备嘛(t ...

  3. PyMySQL插入

    title: PyMySQL插入 author: 杨晓东 permalink: PyMySQL插入 date: 2021-10-02 11:27:04 categories: - 投篮 tags: - ...

  4. nuxt项目中使用store

    首先初始化创建一个nuxt项目 nuxt项目创建以后,内部已自动集成store,所以无需再单独安装和引入 在根目录的store文件夹下新建文件,例如home.js //home.js export c ...

  5. Java流程控制练习

    练习 打印三角形及Debug的使用 public class TestDemo { public static void main(String[] args) { //打印三角形 5行 for(in ...

  6. 每日一抄 Go语言封装qsort快速排序函数

    package qsort /* <GO语言高级编程>设计中案例,仅作为笔记进行收藏. qsort快速排序函数是C语⾔的⾼阶函数,⽀持⽤于⾃定义排序⽐较函数,可以对任意类型的数组进⾏排序. ...

  7. 服务器重启后oracle监听无法打开

    我重启服务器后不知道为啥监听启动不了,试过各种办法都不行,然后把监听删了重新配置就可以了

  8. Drone自动部署配置文件

    .drone.yml 点击查看代码 kind: pipeline # 定义对象类型,还有secret和signature两种类型 type: docker # 定义流水线类型,还有kubernetes ...

  9. APP性能测试——安装耗时测试

    安装耗时: 这里我们用pm命令安装app,来截取安装时间(不要使用adb install安装,因为那样多一个push app的耗时). 示例代码: import os,time,datetime de ...

  10. Git 提交(commit)没有自动生成Change-Id导致无法push

    1). 检查仓储 .git/hook 下面是否有 commit-msg 文件,如果没有可以到下面的地址下载,或者把其他同事的commit-msg文件拷贝到你的.git/hook重新commit即可. ...