当前位置:网站首页>Codeforces Round #803 (Div. 2)vp
Codeforces Round #803 (Div. 2)vp
2022-07-01 05:36:00 【Bzdhxs_nt】
A XOR Mixup
长度为 1 的数列中,有一个数是其他数 X O R XOR XOR 来, 问这个数是多少
随便输出数列中的一个数就行
Code
void solve(){
int n;cin>>n;
vector<int> a(n+1);
int ans = 0;
forr(i,1,n) cin >> a[i];
cout << a[1] << endl;
}
B Rising Sand
当 m = 1 时, 最大的数量就是 ( n − 1 ) / 2 (n-1)/2 (n−1)/2;
m > 1 时,最大数量就是原数列 t o o t a l l too\ tall too tall 的个数;
Code
void solve(){
int n,m;
cin>>n>>m;
vector<int> a(n+1);
forr(i,1,n) cin >> a[i];
if(m == 1){
int res = (n-1)/2;
cout << res << endl;
}
else{
int res = 0;
forr(i,2,n-1){
if(a[i] > a[i-1]+a[i+1]) res++;
}
cout << res << endl;
}
}
C 3SUM Closure
当正数个数或负数个数 >= 3 时,必定不符合条件,输出 no;
当0的个数大于0时,最多有一正一负且枚举1个0即可,否则输出 no;
故,满足条件的数组元素个数最多是4个 O ( n 3 ) O(n^3) O(n3) 枚举即可
Code
void solve(){
int n;
cin>>n;
map<int,int> mp;
vector<int>v;
int t = 0;
int a = 0, b = 0;
forr(i,1,n){
int x;cin>>x;
mp[x] = 1;
if(x>0)a++,v.push_back(x);
else if(x<0)b++,v.push_back(x);
else t++;
}
if(t) v.push_back(0);
if(a>=3||b>=3){
puts("no");
return;
}
forr(i,0,v.size()-1)
forr(j,i+1,v.size()-1)
forr(k,j+1,v.size()-1){
int g = 0;
if(mp[v[i]+v[j]+v[k]]){
g = 1;
}
if(!g){
puts("no");
return ;
}
}
puts("yes");
}
D Fixed Point Guessing
交互题
发现 l o g 1 e 4 ≈ 14 log^{1e4} ≈ 14 log1e4≈14 考虑二分答案
对于区间 [ l , r ] [l,r] [l,r] 内的数有两种情况
值在 [ l , r ] [l,r] [l,r]范围内或者不在
值在区间[l,r]范围内的数也有两种情况
一种是与[l,r]内的值 s w a p swap swap,因而成对存在
另一种是在原位置
故对于[l,r]
若在这个范围内的数的个数为偶数,说明都是进行了 s w a p swap swap 操作
那么答案一定不在这个区间里,二分搜另一个区间
Code
vector<int> ask1(int l,int r){
cout << '?' <<" " << l << " " << r << endl;
vector<int> v;
forr(i,1,r-l+1){
int x;
cin>>x;
v.push_back(x);
}
return v;
}
bool check(vector<int> x,int l, int r){
int cnt = 0;
for(auto i:x){
if(i >= l && i <= r) cnt++;
}
if(cnt%2==0) return 0;
return 1;
}
void solve(){
int n;
cin >> n;
int l = 1, r= n;
int res = 0;
while(l < r){
int mid = l + r >> 1;
int f = 0;
vector<int> b;
b = ask1(l,mid);
int t = check(b,l,mid);
if(t){
r = mid;
}
else{
l = mid + 1;
}
}
cout << '!' <<" " << l << endl;
}
边栏推荐
- C WPF uses dockpanel to realize screenshot box
- Causes of short circuit of conductive slip ring and Countermeasures
- Introduction to 3D modeling and processing software Liu Ligang University of science and technology of China
- Ssgssrcsr differences
- idea启动查看项目端口
- 如何创建一个根据进度改变颜色的进度条
- Leetcode top 100 questions 1 Sum of two numbers
- vsCode函数注解/文件头部注解快捷键
- [excel] column operation, which performs specific column for data in a cell, such as text division by comma, colon, space, etc
- 导数的左右极限和左右导数的辨析
猜你喜欢

El cascade echo failed; El cascader does not echo

Things generated by busybox

Thread process foundation of JUC

0xc000007b the application cannot start the solution normally (the pro test is valid)

多表操作-外键级联操作

Simple implementation of database connection pool

Use and principle of Park unpark

提高企业产品交付效率系列(1)—— 企业应用一键安装和升级

Summary of spanner's paper

导数的左右极限和左右导数的辨析
随机推荐
Chapitre d'apprentissage mongodb: Introduction à la première leçon après l'installation
What can the points mall Games bring to businesses? How to build a points mall?
json数据比较器
Application of industrial conductive slip ring
Mathematical knowledge: finding the number of divisors
新手在挖财开通证券账户安全吗?
Speed regulation and stroke control based on Ti drv8424 driving stepper motor
Deeply understand the underlying implementation principle of countdownlatch in concurrent programming
SSGSSRCSR区别
Causes of short circuit of conductive slip ring and Countermeasures
Lock free concurrency of JUC (leguan lock)
Learn the customization and testing of fpga---ram IP from the bottom structure
Application and principle of ThreadPoolExecutor thread pool
CentOS 7 installed php7.0 using Yum or up2date
0xc000007b the application cannot start the solution normally (the pro test is valid)
Design and application of immutable classes
数字金额加逗号;js给数字加三位一逗号间隔的两种方法;js数据格式化
Multi table operation - foreign key cascade operation
boot+jsp的高校社团管理系统(附源码下载链接)
Wild melon or split melon?