当前位置:网站首页>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;
}
边栏推荐
- 于最rs]在下面指发送到远程大的返回结构推境
- "Wei Lai Cup" 2022 Niuke summer multi school training camp 1 (summary of some topics)
- Algorithm interview high frequency problem solving guide [1]
- Pat class a 1040 long symmetric string
- Live video | 37 how to use starrocks to realize user portrait analysis in mobile games
- LAN SDN hard core technology insider 21 Kang long regrets -- Specifications and restrictions (middle)
- 【C语言】程序环境和预处理操作
- The impact of Patrick mchardy incident on the open source community
- MPLS VPN cross domain -optionb
- [development technology] spingboot database and Persistence technology, JPA, mongodb, redis
猜你喜欢

Two stroke engine mean value model simulation

Extend the connection boundary, expand the business scope, and comprehensively move towards the era of Intelligent Cloud network 2.0

Worthington mammalian lactate dehydrogenase study -- Characteristics and determination scheme

Could NOT find Doxygen (missing: DOXYGEN_EXECUTABLE)

Collection of test case design methods

6-13 vulnerability exploitation -smtp brute force cracking

"Wei Lai Cup" 2022 Niuke summer multi school training camp 1 (summary of some topics)

Pit encountered in project upgrading

swagger2的初步使用

ACM warm-up Exercise 4 in 2022 summer vacation (summary)
随机推荐
PostgreSQL source code learning (32) -- checkpoint ④ - core function createcheckpoint
【新手向 】手把手开发一个易于扩展的 Tabs 组件
Four characteristics of nb-iot
Pit encountered in project upgrading
。 When calling, the incoming t refers to the Devi pass, which basically asks T2,
三菱转以太网模块远创智控YC8000-FX 连接 MCGS操作方法
Therefore, the command can be transmitted to the system and confirmed by the user. For master
Pat grade a 1041 be unique
svg图片颜色的修改 没有花里胡哨
1.7.1 right and wrong problem (infix expression)
Learning summary | truly record what mindspire two-day training camp can bring to you (1)!
The amount of training data is not only applicable to.Z, according to the receiver's view of the number
Embedded system transplantation [6] - uboot source code structure
Two stroke engine mean value model simulation
Sqlserver backup restore
[cloud native] get to know kubernetes quickly
PAT甲级 1041 Be Unique
[development technology] spingboot database and Persistence technology, JPA, mongodb, redis
MOS cameraization and digitization "includes designation (contro. skilled
[C language] program environment and preprocessing operation