当前位置:网站首页>Codeforces Round #807 (Div. 2) A - D
Codeforces Round #807 (Div. 2) A - D
2022-07-22 20:35:00 【追烽】
Codeforces Round #807 (Div. 2)
提交情况


参考
Codeforces Round #807 (Div. 2) A~E
A. Mark the Photographer
标签
构造
题意

代码
#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
标签
构造
题意

思路
把前导零去除, 然后把剩余的 0 填充为 1, 每次填充花费 1 个操作数, 填充完后依次把所有非零值加到 a[n].
代码
#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
标签
构造, 二分, 递归
题意

思路
以前出过的题目.
代码
#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
标签
构造
题意

思路

重点是把每次操作看作一个连续相同数字段的端点的移动.
代码
#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;
}
边栏推荐
- Zhimeng dedecms forgot to manage the background password retrieval method
- J9数字论:什么是 Web3.0?Web3.0 有哪些特征?
- 导出功能单独调用
- 小程序毕设作品之微信校园二手书交易小程序毕业设计成品(8)毕业设计论文模板
- Interface Fiddler introduction and installation
- 小程序毕设作品之微信酒店预订小程序毕业设计(8)毕业设计论文模板
- Shell script
- 二叉树的遍历
- GNU LD script command language (I)
- 从BIO到实现简单多人聊天室功能--IO模型
猜你喜欢
随机推荐
企业生产线改善毕业论文【Flexsim仿真实例】
dispatch_once 的秘密
Null and nullptr
Google cloud and Oracle cloud are "hot"? It is imperative to deploy cross cloud disaster recovery!
低代码服务商ClickPaaS与毕普科技完成战略合并,共同打造工业数字化底座
[FAQ] common reasons and solutions for the failure of in app payment services to pull up the payment page
小程序毕设作品之微信校园二手书交易小程序毕业设计成品(5)任务书
小程序毕设作品之微信酒店预订小程序毕业设计(6)开题答辩PPT
LAN SDN technology hard core insider - what's in the prequel CPU?
ES6 solves asynchronous problems
LAN SDN technology hard core insider - 02 forward multi-core technology for Moore's law for one second
园区招商难在“哪”?产业园区招商引资困点难点问题盘点
Vector3.Lerp
标签平滑(label smoothing)
基于API调用管理的SDN应用层DDoS攻击防御机制
LaTeX编写中文实验进展汇报
小程序毕设作品之微信校园二手书交易小程序毕业设计成品(1)开发概要
How to do if the control panel program cannot be uninstalled? Compulsory uninstallation software tutorial
Flutter内存泄漏检测
基于以太坊状态数据库的攻击与防御方案








