Codeforces Round #803 (Div. 2) A-D 刚vp完还没补题
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完还没补题的更多相关文章
- 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 ...
- 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 ...
- 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.直接暴力判断即 ...
- Codeforces Round #424 (Div. 2, rated, based on VK Cup Finals)A B题
当时晚上打CF时候比较晚,加上是集训期间的室友都没有晚上刷题的习惯,感觉这场CF很不在状态.A题写复杂WA了一发后去厕所洗了个脸冷静了下,换个简单写法,可是用cin加了ios::sync_with_s ...
- Codeforces Round #554 (Div. 2) B. Neko Performs Cat Furrier Transform(思维题+log2求解二进制位数的小技巧)
传送门 题意: 给出一个数x,有两个操作: ①:x ^= 2k-1; ②:x++; 每次操作都是从①开始,紧接着是② ①②操作循环进行,问经过多少步操作后,x可以变为2p-1的格式? 最多操作40次, ...
- 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 ...
- 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 ...
- 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 ...
- 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 ...
- 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: ...
随机推荐
- K8s试验环境搭建(一)
一.kubernetes简介 1.什么是kubernetes? kubernetes是google公司用go语言开发的一套容器编排系统,简称k8s:它主要用于容器编排:所谓容器编排简单的我们可以理解为 ...
- SAP 结构转JSON
*使用方式 jsonstr = zui2_json=>serialize( data = ls_in compress = abap_true pretty_name = zui2_json=& ...
- SHR之员工合同解除
员工合同解除HRContractInfoFacadeControllerBean 这块的意思的源码可以自行翻阅该源码. 调用员工的实现这个合同自动解除 String sql="select ...
- 2022-04-14内部群每日三题-清辉PMP
1.项目经理资源有限,无法获得更多资源.项目经理应该使用什么技术来充分利用现有资源,而不会令项目完成时间延期? A.资源平滑 B.资源平衡 C.快速跟进 D.赶工 2.正在审查问题日志的项目经理注意到 ...
- Unity中的批处理优化与GPU Instancing【转】
我们都希望能够在场景中投入一百万个物体,不幸的是,渲染和管理大量的游戏对象是以牺牲CPU和GPU性能为代价的,因为有太多Draw Call的问题,最后我们必须找到其他的解决方案.在本文中,我们将讨论两 ...
- Software--电商平台系统--P2 支撑基础设施 Infrastructure
2018-01-11 18:19:49 架构 客户体验 Ajax 交互技术. 网站快速加载且响应灵敏,则应该缓存商品数据. 灵活的缓存机制,以支持任何类型的存储(即分布式存储或内存中存储). 日志功 ...
- 【SQL Server 】Having——聚合函数的筛选
在SQL Server 中,有Having关键字. 它的作用是:因为Where关键字无法与聚合函数一起使用,所以Having子句可以在我们筛选分组后各自组成数据. 1 -- 筛选出成绩大于等于500的 ...
- SpringBoot整合mqtt协议,实现订阅topic并将消息存储到mysql数据库
所需依赖如下: <dependencies> <dependency> <groupId>org.springframework.boot</groupId& ...
- Linux基础第十一章:日志文件及如何使用rsyslog搭建小型日志服务器
一.日志文件 1.日志作用 2.常用日志 3.日志级别 二.Rsyslog日志处理系统 1.使用Rsyslog创建日志有点 2.Rsyslog配置文件解析 3.使用rsyslog将ssh服务的日志单独 ...
- UniCode 下char*转CString ,利用MultiByteToWideChar进行转换,中文乱码的解决方案
//计算char *数组大小,以字节为单位,一个汉字占两个字节 int charLen = strlen(sText); //计算多字节字符的大小,按字符计算. int len = MultiByte ...