当前位置:网站首页>Codeforces Round #803 (Div. 2)(A~D)
Codeforces Round #803 (Div. 2)(A~D)
2022-07-02 10:21:00 【_dawn°】
复健失败 xD
C题花了好久搞出来然后fst了,笑死,要不是因为没出六次的新手保护期就掉分了hhhhhh
A. XOR Mixup

给出一个数组,其中某一个数是其他数异或和,输出这个数。
思路:其中某个数是其他数的异或和,那就说明这个数组的异或和是0,根据异或的性质,其中任何一个数都可以作为其他所有数的异或和,答案就是随便输出数组中的一个数即可。
AC Code:
#include <bits/stdc++.h>
typedef long long ll;
#define INF 0x3f3f3f3f
const int mod=1e9+7;
const int N=1e3+5;
int t,n;
int a[N];
int main(){
std::ios::sync_with_stdio(false);
std::cin.tie(0);
std::cout.tie(0);
std::cin>>t;
while(t--){
std::cin>>n;
for(int i=1;i<=n;i++){
std::cin>>a[i];
}
std::cout<<a[n]<<'\n';
}
return 0;
}B. Rising Sand

给出一系列的沙堆,定义一个沙堆过于高:这个沙堆的高度大于相邻两堆之和。给出一个k,每次可以对连续的k堆操作,每一堆+1,问经过若干次操作后最多有多少沙堆过于高。
思路:分类讨论:k为1时,因为我们可以对任意的一堆进行操作而不影响相邻的高度,我们可以使它尽可能的多,即每隔一堆就有一个;k非1时,每次修改都会影响相邻的高度,使其相对高度是不变的,我们大可以推断k>1时无论多少次修改都是对过于高的个数无影响。
AC Code:
#include <bits/stdc++.h>
typedef long long ll;
#define INF 0x3f3f3f3f
const int mod=1e9+7;
const int N=2e5+5;
int t,n,k;
int a[N];
int main(){
std::ios::sync_with_stdio(false);
std::cin.tie(0);
std::cout.tie(0);
std::cin>>t;
while(t--){
std::cin>>n>>k;
int ans=0;
for(int i=1;i<=n;i++){
std::cin>>a[i];
}
if(k==1){
int res=n-2;
std::cout<<(res+1)/2<<'\n';
continue;
}
for(int i=2;i<n;i++){
if(a[i]>a[i+1]+a[i-1]) ans++;
}
std::cout<<ans<<'\n';
}
return 0;
}C. 3SUM Closure

给出一个数组,若对于数组中任意三个数的和都存在于数组中,那么这个数组是3SUM-closed的。现给出数组,判断其是否为3SUM-closed。
思路:若数组中同时存在三个正数或三个负数,那会不断增大或减小最大值和最小值,不符合条件;这样满足条件时,数组中我们可以视为更多的元素为0,在有限个数内直接暴力枚举即可。
AC Code:
#include <bits/stdc++.h>
#define int long long
const int N=2e5+5;
int t,n;
int a[N];
std::vector<int>vec;
std::map<int,int>mp;
bool check(){
int len=vec.size();
for(int i=0;i<len;i++){
for(int j=i+1;j<len;j++){
for(int k=j+1;k<len;k++){
if(!mp[vec[i]+vec[j]+vec[k]]) return false;
}
}
}
return true;
}
signed main(){
std::ios::sync_with_stdio(false);
std::cin.tie(0);
std::cout.tie(0);
std::cin>>t;
while(t--){
std::cin>>n;
int l=0,s=0;
vec.clear();
mp.clear();
for(int i=1;i<=n;i++){
std::cin>>a[i];
if(a[i]!=0) vec.push_back(a[i]);
else{
if(!mp[0]) vec.push_back(a[i]);
}
mp[a[i]]++;
if(a[i]>0) l++;
if(a[i]<0) s++;
}
if(l>=3||s>=3){
std::cout<<"NO"<<'\n';
continue;
}
std::cout<<(check()?"YES":"NO")<<'\n';
}
return 0;
}os:蛤蛤
D. Fixed Point Guessing

给出一个奇数长度的排列,两两进行位置互换,那最后必有一个元素未交换位置,每次询问可以得到一段区间内的所有数,在15次询问内找到这个数。
思路:我们通过询问可以知道有多少数是原来这个区间的,因为一开始的数组必是1~n排列。那么这些数有两种可能,一是与这个区间的值进行了交换,两一种情况是未进行交换。若没进行交换的元素在这个区间,那么这个区间长度必为奇数,否则没有交换的区间一定在别的区间,对于这样的考虑,使用二分,可以满足在15次询问内得到答案。
(交互题输出后加 "fflush(stdout) or cout.flush()" 是要清空缓存区,直接使用 std::endl 清空也是一样的)
AC Code:
#include <bits/stdc++.h>
typedef long long ll;
const int N=1e4+5;
int t,n;
int a[N];
void ask(int l,int r){
std::cout<<"? "<<l<<' '<<r<<std::endl;
for(int i=l;i<=r;i++){
std::cin>>a[i];
}
}
int main(){
std::ios::sync_with_stdio(false);
std::cin.tie(0);
std::cout.tie(0);
std::cin>>t;
while(t--){
std::cin>>n;
int l=1,r=n;
while(l<r){
int mid=l+r>>1;
ask(l,mid);
int cnt=0;
for(int i=l;i<=mid;i++){
cnt+=(a[i]>=l&&a[i]<=mid);
}
if(cnt&1) r=mid;
else l=mid+1;
}
std::cout<<"! "<<l<<std::endl;
}
return 0;
}os:交互题其实和普通题是一样的欸,就是形式比较新一些hhh
若有错误请指教,谢谢!
边栏推荐
- Node.js通过ODBC访问PostgreSQL数据库
- [技术发展-22]:网络与通信技术的应用与发展快速概览-2- 通信技术
- rxjs Observable 自定义 Operator 的开发技巧
- Why can't d link DLL
- selenium,元素操作以及浏览器操作方法
- [Unity]使用GB2312,打包后程序不正常解决方案
- How much do you know about free SSL certificates? The difference between free SSL certificate and charged SSL certificate
- Everyone believes that the one-stop credit platform makes the credit scenario "useful"
- 口袋奇兵点评
- Browser driven Download
猜你喜欢
![[technology development-22]: rapid overview of the application and development of network and communication technology-2-communication Technology](/img/a7/44609a5acf25021f1fca566c3d8c90.png)
[technology development-22]: rapid overview of the application and development of network and communication technology-2-communication Technology

Don't spend money, spend an hour to build your own blog website
【文档树、设置】字体变小

Operation tutorial: how does easydss convert MP4 on demand files into RTSP video streams?

不会看器件手册的工程师不是个好厨子

ensp简单入门

How to modify the error of easydss on demand service sharing time?

Essential for operation and maintenance - Elk log analysis system

A better database client management tool than Navicat

为什么switch 的default后面要跟break?
随机推荐
D为何链接不了dll
How much do you know about free SSL certificates? The difference between free SSL certificate and charged SSL certificate
How to use SAP's metadata framework (MDF) to build custom business rules?
Launcher启动过程
Bridge of undirected graph
Subcontracting configuration of uniapp applet subpackages
使用BLoC 构建 Flutter的页面实例
Pocket Raider comments
Add sequence number column to query results in MySQL
Runhe hi3516 development board openharmony small system and standard system burning
Let juicefs help you with "remote backup"
OpenAPI generator: simplify the restful API development process
[technology development-22]: rapid overview of the application and development of network and communication technology-2-communication Technology
Use bloc to build a page instance of shutter
Origin绘制热重TG和微分热重DTG曲线
Simple introduction to ENSP
Node. JS accessing PostgreSQL database through ODBC
[Unity]使用GB2312,打包后程序不正常解决方案
Winter vacation daily question - lucky numbers in the matrix
[youcans' image processing learning course] general contents