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. Unity中的深度测试相关知识与问题

    https://www.jianshu.com/p/f420b55edd0b?utm_campaign=hugo

  2. P1067 [NOIP2009 普及组] 多项式输出 题解

    目录 题目 要注意的地方 code 题目 P1067 [NOIP2009 普及组] 多项式输出 要注意的地方 是不是常数项 是不是1 或 -1 输入的是不是第一个 ^1 负数 code #includ ...

  3. leetcode 310. 最小高度树 【时间击败70.67%】 【内存击败89.04%】

    数组替代队列,从超时到击败70%,用tree[0]替代new一个新的ArrayList,上升10% 思想是遍历一遍,删除度为1的节点,答案只可能为1或2 1 public List<Intege ...

  4. kibana启动及导出PDF报错

    kibana启动及导出PDF报错,可能是由于kibana需要的系统依赖没有安装 CentOS/RHEL系统需要安装以下依赖: ipa-gothic-fonts xorg-x11-fonts-100dp ...

  5. Dockerfile 参考

    Dockerfile:FROM openjdk:8u252-jdkENV JHIPSTER_SLEEP=0 \ JAVA_OPTS="" \ LOGFILE="" ...

  6. 模块二:os模块、sys模块、json模块、pickle模块,包

    os模块 1 os模块是与操作系统交互的一个接口 2 import os: 3 1.获取当前工作目录 4 print(os.getcwd()) 5 6 2.切换到D:\yuan文件目录 7 os.ch ...

  7. 实时中文语音克隆——开源项目MockingBird体验

    [引子] 在今年大型网络攻防演练前不久,笔者接到一个公司的座机号码来电,上来就问防守准备得怎么样了,哪里还有不足等.等等,这声音不认识,笔者第一反应就是蓝军(Red Team)来进行社会工程攻击,于是 ...

  8. <二>JMeter/Navicat for MYSQL运行案例

    一.JMeter 1. 下载地址:http://jmeter.apache.org/download_jmeter.cgi 2. 选择适合的版本进行下载,如下: 3. 将下载好的压缩包解压到任意文件夹 ...

  9. vue中页面渲染完成之后获取元素的属性

    data() { return { message : [], }; }, watch:{ message:function(){ this.$nextTick(function(){ //方法 }) ...

  10. pycharm怎么查看某个包pycharm怎么查看某个包的源码的源码

    安装ctrl点击对应的函数名或是包名即可