当前位置:网站首页>Codeforces Round #807 (Div. 2) A - D
Codeforces Round #807 (Div. 2) A - D
2022-07-24 04:02:00 【Chasing the beacon】
Codeforces Round #807 (Div. 2)
Submission


Reference resources
Codeforces Round #807 (Div. 2) A~E
A. Mark the Photographer
label
structure
The question

Code
#include<bits/stdc++.h>
#define FOR(i,a,b) for(int i=(a);i<=(b);++i)
using namespace std;
void solve(){
int n,x;cin>>n>>x;
int a[1007]={
};
FOR(i,1,2*n) cin>>a[i];
sort(a+1,a+2*n+1);
int ans=1;
FOR(i,1,n) if(a[i+n]-a[i]<x) ans=0;
if(ans) cout<<"YES\n";
else cout<<"NO\n";
}
signed main(){
cin.tie(0)->sync_with_stdio(0);
int T;cin>>T;
while(T--){
solve();
}
return 0;
}
B. Mark the Dust Sweeper
label
structure
The question

Ideas
Remove leading zeros , And then put the rest of 0 Fill in with 1, Cost per fill 1 Operands , After filling, add all non-zero values to a[n].
Code
#include<bits/stdc++.h>
#define FOR(i,a,b) for(int i=(a);i<=(b);++i)
using namespace std;
#define int long long
int a[200007];
void solve(){
int n;cin>>n;
FOR(i,1,n) cin>>a[i];
int st=1;
while(a[st]==0) st++;
int ans=0;
FOR(i,st,n-1){
if(a[i]==0) ans++;
else ans+=a[i];
}
cout<<ans<<endl;
}
signed main(){
cin.tie(0)->sync_with_stdio(0);
int T;cin>>T;
while(T--){
solve();
}
return 0;
}
C. Mark and His Unfinished Essay
label
structure , Two points , recursive
The question

Ideas
Reference resources C. Sereja and Prefixes.
Previous topics .
Code
#include<bits/stdc++.h>
#define FOR(i,a,b) for(int i=(a);i<=(b);++i)
using namespace std;
#define int long long
struct node{
int prel,prer,l,r;
};
vector<node> a;
char s[200007];
int n;
int ask(int k){
int l=0,r=a.size()-1;
while(l<r){
int mid=(l+r+1)/2;
if(a[mid].l<=k) l=mid;
else r=mid-1;
}
if(a[r].r<=n) return k;
else return ask(a[r].prel+k-a[r].l);
}
void solve(){
a.clear();
memset(s,0,sizeof s);
int c,q;
cin>>n>>c>>q;
FOR(i,1,n) cin>>s[i];
int len=n;
a.push_back({
1,n,1,n});
FOR(i,1,c){
int l,r;cin>>l>>r;
a.push_back({
l,r,len+1,len+1+r-l});
len=len+1+r-l;
}
FOR(i,1,q){
int k;cin>>k;
cout<<s[ask(k)]<<endl;
}
}
signed main(){
cin.tie(0)->sync_with_stdio(0);
int T;cin>>T;
while(T--){
solve();
}
return 0;
}
D. Mark and Lightbulbs
label
structure
The question

Ideas

The key point is to regard each operation as the movement of the endpoint of a continuous same number segment .
Code
#include<bits/stdc++.h>
#define FOR(i,a,b) for(int i=(a);i<=(b);++i)
using namespace std;
#define int long long
struct node{
int l,r;
};
const int N = 2e5+7;
string s1,s2;
vector<node> n1,n2;
int solve(){
n1.clear(); n2.clear();
int n;cin>>n;
cin>>s1>>s2;
if(s1==s2) return 0;
if(s1[0]!=s2[0] or s1[n-1]!=s2[n-1]) return -1;
FOR(i,0,n-1){
while(i<=n-1 and s1[i]=='0') i++;
if(i==n) break;
int l=i;
while(i<=n-1 and s1[i]!='0') i++;
n1.push_back({
l,i-1});
}
FOR(i,0,n-1){
while(i<=n-1 and s2[i]=='0') i++;
if(i==n) break;
int l=i;
while(i<=n-1 and s2[i]!='0') i++;
n2.push_back({
l,i-1});
}
if(n1.size()!=n2.size()) return -1;
int ans=0;
FOR(i,0,n1.size()-1){
ans+=abs(n1[i].l-n2[i].l)+abs(n1[i].r-n2[i].r);
}
return ans;
}
signed main(){
cin.tie(0)->sync_with_stdio(0);
int T; cin>>T;
while(T--) cout<<solve()<<endl;
return 0;
}
边栏推荐
- Extend the connection boundary, expand the business scope, and comprehensively move towards the era of Intelligent Cloud network 2.0
- Matlab Simulink simulation of lithium iron phosphate battery
- 1.7.1 正误问题(中缀表达式)
- Sqlserver backup restore
- Workbnech application of dynamixel steering gear under ROS
- D2DEngine食用教程(3)———将渲染目标导出为图像文件
- Matlab ode45 solving differential equations
- Therefore, the command can be transmitted to the system and confirmed by the user. For master
- [C language] program environment and preprocessing operation
- Demining game (analysis)
猜你喜欢

Pat grade a 1041 be unique

Jinglianwen technology provides 3D point cloud image annotation service

PAT甲级 1040 Longest Symmetric String

Technical dry goods | evaluation index based on mindspire detailed perflexity language model

【云原生】快速了解Kubernetes

Learning summary | truly record what mindspire two-day training camp can bring to you (1)!

swagger2的初步使用

Preliminary use of swagger2

MPLS VPN cross domain -optionb

Machine learning notes - image homography estimation based on deep learning (homographynet)
随机推荐
嵌入式系统移植【6】——uboot源码结构
MLP-多层感知机
Collection of test case design methods
MySQL cannot be accessed. Navicat prompt: is not allowed to connect to this MySQL server
PAT甲级 1041 Be Unique
6-15 vulnerability exploitation SMB rce remote command execution
Worthington hydroxysteroid dehydrogenase technical description and determination scheme
The pit trodden by real people tells you to avoid the 10 mistakes often made in automated testing
Worthington mammalian lactate dehydrogenase study -- Characteristics and determination scheme
Worthington: characteristics and other parameters of hexokinase from yeast
Redis sentinel mode, master node check script
Hardware knowledge 3 -- IIC protocol
Avoid mistakes, common appium related problems and Solutions
Baidu search cracking down on pirated websites: why Internet content infringement continues despite repeated prohibitions
ACM warm-up Exercise 4 in 2022 summer vacation (summary)
[C language] program environment and preprocessing operation
DOM related method concepts
An accident caused by MySQL misoperation, and "high availability" can't withstand it
Send data 1010_ 1. The number of bytes passed by the sender
6-13 vulnerability exploitation -smtp brute force cracking