当前位置:网站首页>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
若有错误请指教,谢谢!
边栏推荐
- Essential for operation and maintenance - Elk log analysis system
- D language, possible 'string plug-ins'
- MAC (MacOS Monterey 12.2 M1) personal use PHP development
- The second anniversary of the three winged bird: the wings are getting richer and the take-off is just around the corner
- 错误:EACCES:权限被拒绝,访问“/usr/lib/node_modules”
- [Unity]使用GB2312,打包后程序不正常解决方案
- How to modify the error of easydss on demand service sharing time?
- OpenAPI generator: simplify the restful API development process
- Clean up system cache and free memory under Linux
- ensp简单入门
猜你喜欢

Three methods of finding LCA of the nearest common ancestor

为什么switch 的default后面要跟break?

MAC (MacOS Monterey 12.2 M1) personal use PHP development
![[OpenGL] notes 29. Advanced lighting (specular highlights)](/img/6e/56bc7237f691a4355f0b7627b3003e.png)
[OpenGL] notes 29. Advanced lighting (specular highlights)

浏览器驱动的下载

Téléchargement par navigateur

What are eNB, EPC and PGW?

Everyone believes that the one-stop credit platform makes the credit scenario "useful"

你的 Sleep 服务会梦到服务网格外的 bookinfo 吗

Origin plots thermogravimetric TG and differential thermogravimetric DTG curves
随机推荐
P1347 排序(拓扑 + spfa判断环 or 拓扑[内判断环])
Use bloc to build a page instance of shutter
OpenAPI generator: simplify the restful API development process
Countermeasures for the failure of MMPV billing period caused by negative inventory of materials in SAP mm
D为何链接不了dll
Qt新项目_MyNotepad++
QT how to set fixed size
使用BLoC 构建 Flutter的页面实例
Node.js通过ODBC访问PostgreSQL数据库
Partner cloud form strong upgrade! Pro version, more extraordinary!
[youcans' image processing learning course] general contents
口袋奇兵点评
Quantum three body problem: Landau fall
I did it with two lines of code. As a result, my sister had a more ingenious way
[技术发展-22]:网络与通信技术的应用与发展快速概览-2- 通信技术
Skillfully use SSH to get through the Internet restrictions
uniapp小程序 subPackages分包配置
JS reverse massive creative signature
OpenFOAM:lduMatrix&lduAddressing
Numpy array calculation