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. window.open在打开pdf时直接下载而不是查看

    一般这是url请求的原因导致的, 可以考虑这种写法 window.open(link+'?response-content-type=application/pdf') 加上后面这段可以转为查看

  2. laravel 软删除的使用

    1.模型层 引用类use Illuminate\Database\Eloquent\SoftDeletes;class类中引用软删除use SoftDeletes;然后执行正常的删除,列表已经不显示, ...

  3. 启动Apache出现错误Port 80 in use by "Unable to open process" with PID 4!

    22:15:30  [Apache] Problem detected! 22:15:30  [Apache] Port 80 in use by "Unable to open proce ...

  4. 自定义go语言日志输出

    自定义输出符合下列需求: 1.含两类日志输出方式:调试模式下输出到控制台:生产环境输出到日志文件 2.调用不同的函数/方法构造不同的输出方式,后续只需调用日志级别对应的函数即可输出该级别日志 工具构造 ...

  5. C# 屏蔽词过滤

    参考:https://www.cnblogs.com/kubidemanong/p/10834993.html public class TreeNode { public char Char; pu ...

  6. Spring RMI 介绍

    Spring RMI RMI全称是Remote Method Invocation-远程方法调用,是纯Java的网络分布式应用系统的核心解决方案之一.Java RMI 支持存储于不同地址空间的程序级对 ...

  7. php相关知识总结

    class Father{ public static function getStatic(){ return new static(); } public static function getS ...

  8. 通用CSS命名惯例

    通用的 CSS 命名惯例 在参与规模庞大.历时漫长.且参与人数众多的项目时,要确保每一行代码都像是同一个人编写的:这就要求所有开发者,都遵守相同的代码规范.在先前的文章前端项目开发规范意见,从宏观角度 ...

  9. Coder vs Programmer: Difference You Should Know

    In this tech-driven world, you may have heard the terms 'coder' and 'programmer' used interchangeabl ...

  10. 在uni-app中调用高德地图去导航

    1.判断一下是不是在微信环境 2.微信环境调用微信自带的地图导航 3.h5环境跳转去高德地图 guide() { let self = this; console.log("self.lat ...