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. encodeURI和encodeURIComponent

    encodeURI和encodeURIComponent的作用对象都是URL,唯一的区别就是编码的字符范围: encodeURI不会对ascii字母.数字.~!@#$&*()=:/,;?+' ...

  2. React中使用CSS的N种方式

    1.在组件中直接使用style,注意,div1各个属性值加双引号 const div1 = { width: "300px", margin: "30px auto&qu ...

  3. 请求/响应拦截器 给请求添加token认证

  4. varchar(1)占用几个字节

    在version4之前,MySQL中varchar长度是按字节:而version5之后,按字符.如varchar(6),在version4,表示占用6个字节,而在version5中,表示占用6个字符. ...

  5. redis分布式锁实现,setnx,nodejs版本

    const redis = require('ioredis'); const clienId = Math.random() * 100; //模拟客户端Id const lockKey = 'te ...

  6. Ajax同步和异步的区别,如何解决跨域的问题

    同步的概念应该是来自于OS中关于同步的概念:不同进程为协同完成某项工作而在先后次序上调整(通过阻塞,唤醒等方式),同步强调的是顺序性,谁先谁后,异步则不存在这种顺序性. 同步:浏览器访问服务器请求,用 ...

  7. iOS 高级面试题

    面试题 iOS 基础题 分类和扩展有什么区别?可以分别用来做什么?分类有哪些局限性?分类的结构体里面有哪些成员? 讲一下atomic的实现机制:为什么不能保证绝对的线程安全(最好可以结合场景来说)? ...

  8. ZSTUOJ刷题11:Problem D.--零起点学算法106——首字母变大写

    Problem D: 零起点学算法106--首字母变大写 Time Limit: 1 Sec  Memory Limit: 64 MBSubmit: 18252  Solved: 5211 Descr ...

  9. axios基本配置

    点击查看代码 <!-- axios基础用法 --> <script> /** * axios:一款基于promise设计模式封装的ajax库(JQ中的ajax就是最普通的aja ...

  10. Vue3 + echarts 统一封装

    1. 新建 echartsLib.js 文件,统一导入需要的组件 import * as echarts from "echarts/core"; import { SVGRend ...