Codeforces Round #807 (Div 2.) A·B·C
div round Codeforces
2023-06-13 09:12:22 时间
A. Mark the Photographer
原题链接
思想
- 将所有人的身高存入数组 ,用
sort
排序 - 利用双指针,以
n
为分界线,判断是否满足条件 - 前
n
个人的身高+ x
小于等于后n
个人的身高
代码
#include <bits/stdc++.h>
using namespace std;
const int N=1e6+3;
int a[N];
int main(){
int t;
scanf("%d",&t);
while(t--){
int n,x;
scanf("%d%d",&n,&x);
for(int i=0;i<n*2;i++) scanf("%d",&a[i]);
sort(a,a+n*2); //排序
bool flag=1;
for(int i=0,j=n;i<n;i++,j++){ //i从0~n-1 j从n~2*n-1
if(a[j]-a[i]<x){
flag=0;
break;
}
}
if(flag) printf("YES\n");
else printf("NO\n");
}
return 0;
}
B. Mark the Dust Sweeper
原题链接
思想
- 由题意可知当i与j之间不存在a_i=0时,可以进行操作
- 则对存入数组的数据进行遍历,直到从头遍历到a_i=0为止
- 此时,后方的a_i=0的房间都可以通过a_j\ne 0的房间来填充一次,使得操作继续
代码
#include <bits/stdc++.h>
using namespace std;
int t;
const int N=1e6+3;
int a[N];
int main(){
cin>>t;
while(t--){
int n;
cin>>n;
for(int i=0;i<n;i++) cin>>a[i];
int p=0;
while(p<n&&a[p]==0) p++;
long long cnt=0;
for(int i=p;i<n-1;i++){
cnt+=a[i];
if(a[i]==0) cnt++;
}
cout<<cnt<<endl;
}
return 0;
}
C. Mark and His Unfinished Essay
原题链接
思想
- 由于数据范围暴大,想用
string
存下来是不可能的 - 对于每次的
copy
操作,记录l
和r
- 同时记录
copy
之后的l
和r
的新位置,记为nl
和nr
- 对于每次询问,要找到
k
所在的nl
和nr
的区间 - 即要找到进行第几次
copy
操作后,满足l
和r
更新的区间nl
和nr
,使得nl <= k <= nr
- 找到后,将
k
更新为k' = k - (nl - l)
,使得k'
在l
和r
所在的区间内,即l <= k' <= r
- 不断重复上述步骤更新
k
,直到1 <= k <= n
- 由于操作次数很少,在寻找对应区间时可以直接从大到小进行枚举
代码
#include <bits/stdc++.h>
using namespace std;
const int N=1e6+3;
typedef long long LL;
LL l[N],r[N],nl[N],nr[N];
//l和r数组存储每次copy的l和r
//nl和nr数组存储copy之后,l和r的位置
void solve(){
LL n,m,q;
cin>>n>>m>>q;
string s;
cin>>s;
nl[0]=0,nr[0]=n;
for(int i=1;i<=m;i++){
cin>>l[i]>>r[i];
nl[i]=nr[i-1]+1; //更新nl
nr[i]=nl[i]+(r[i]-l[i]+1)-1; //更新nr
}
while(q--){
LL k;
cin>>k;
for(int i=m;i>=1;i--){ //枚举区间
if(nl[i]<=k&&k<=nr[i]) k-=nl[i]-l[i];
}
cout<<s[k-1]<<endl;
}
}
int main(){
LL t;
cin>>t;
while(t--){
solve();
}
return 0;
}
后记
- A题肥肠煎蛋,没有被hack也没什么感觉
- B题比赛时写麻烦了,最后TLE了,补题才发现自己把自己绕晕了
- C题实在是干到怀疑狗生了,前后搞了好几个小时才绕过来弯,希望自己以后不要这么笨了
- 剩下的题实在是不行,毕竟还是个大弱鸡,交给未来吧,加油!!!
相关文章
- JQuery Div scrollTop ScrollHeight
- Edu Codeforces Round 115 (Div. 2)
- Codeforces Round #826 (Div. 3)(A~D)
- Codeforces Round #825 (Div. 2) (A~C1)
- Educational Codeforces Round 137 (Rated for Div. 2)(A~E)
- Codeforces Round #828 (Div. 3) (A~D)
- Oracle 求整除法 DIV 的应用(oracle相除取整)
- C语言div()函数:求两个数的商和余数
- 函数探索MySQL中Round函数的神秘之处(mysql中round)
- ination神秘的oracle预言-洞察未来(oracle div)
- HTML结构化:实践DIV+CSS网页布局入门指南
- js实现DIV的一些简单控制
- 大家需要掌握的html下SPAN和DIV的区别
- IE6,IE7和firefox对DIV的支持区别
- 常用的DIV+CSS的基本框架结构但不推荐都放一个div里
- jquery实现div拖拽宽度示例代码
- javascript实现div浮动在网页最顶上并带关闭按钮效果实例
- javascript获取设置div的高度和宽度兼容任何浏览器
- js通过八个点拖动改变div大小的实现方法