【Codeforces】Round #491 (Div. 2) 总结
程序员文章站
2022-05-12 12:22:00
...
【Codeforces】Round #491 (Div. 2) 总结
这次尴尬了,D题fst,E没有做出来。。。。
不过还好,rating只掉了30,总体来说比较不稳,下次加油
A:If at first you don’t succeed…
SB题,就是注意一下特判就好了,然后我一开始wa了三次。。。
#include<bits/stdc++.h>
using namespace std;
int read(){
int ans=0,w=1;char c=getchar();
while(!isdigit(c)&&c!='-')c=getchar();
if(c=='-')c=getchar(),w=-1;
while(isdigit(c))ans=ans*10+c-'0',c=getchar();
return ans*w;
}
int main(){
int a=read(),b=read(),c=read(),d=read();
if(a+b-c>=d||a>d||b>d||c>d||c>a||c>b){
cout<<"-1";
}else cout<<d-a-b+c;
return 0;
}
B:Getting an A
比较稳过的一题
排序,从最小的一位开始贪心
#include<bits/stdc++.h>
using namespace std;
int read(){
int ans=0,w=1;char c=getchar();
while(!isdigit(c)&&c!='-')c=getchar();
if(c=='-')c=getchar(),w=-1;
while(isdigit(c))ans=ans*10+c-'0',c=getchar();
return ans*w;
}
double a[110];
int n;
int main(){
cin>>n;
for(int i=1;i<=n;i++)
cin>>a[i];
sort(a+1,a+n+1);
double sum=0;
for(int i=1;i<=n;i++)sum+=a[i];
int ans=0;double minv=4.5*(double)n;
while(sum<minv){
ans++;
sum=sum-a[ans]+5;
}
cout<<ans;
return 0;
}
C:Candies
虽然我也不知道复杂度是什么,但是二分+check可以稳过,只用枚举k然后暴力检查就好,一开始因为二分写挂T了,后面顺利AC
#include<bits/stdc++.h>
using namespace std;
#define LL long long
LL n;
bool check(LL w,LL p){
LL tmp=0,pic=p;
while(pic>0){
if(w>=pic){
tmp+=pic;
return tmp*2>=p;
}
tmp+=w;
pic-=w;
pic-=pic/10;
if(tmp*2>=p)return 1;
}
return 0;
}
void solve(LL p){
LL l=1,r=p,ans=0;
while(l<=r){
LL mid=(l+r)>>1;
if(check(mid,p))r=mid-1,ans=mid;
else l=mid+1;
}
cout<<ans<<endl;
}
int main(){
cin>>n;
solve(n);
return 0;
}
D:Bishwock
DP很裸,就是需要注意一下当有连续三个位置(包含两个字符串)都是空的,可以放进两个
000 -> XX + 0X = XXX
000 -> X0 + XX = XXX
#include<bits/stdc++.h>
using namespace std;
int f[110]={0};
char c[2][110];
int mx[4]={0,0,1,1};
int my[4]={0,1,0,1};
bool check(int pos,int id){
for(int i=0;i<4;i++){
if(i==id)continue;
int nx=pos-mx[i],ny=1-my[i];
if(c[ny][nx]=='X')return 0;
}
return 1;
}
bool emp(int pos){
return c[0][pos]=='0'&&c[1][pos]=='0';
}
int main(){
scanf("%s%s",c[0],c[1]);
int n=strlen(c[0]);
for(int i=1;i<n;i++){
f[i]=f[i-1];
for(int j=0;j<4;j++)
if(check(i,j))f[i]=max(f[i],f[i-2]+1);
if(i>=2&&emp(i)&&emp(i-1)&&emp(i-2))f[i]=max(f[i],f[i-3]+2);
}
cout<<f[n-1];
return 0;
}
E:Bus Number
F:Concise and clear
推荐阅读
-
Codeforces Round #595 (Div. 3)D1D2 贪心 STL
-
Codeforces Round #655 (Div. 2) A. Omkar and Completion
-
Codeforces Round #656 (Div. 3)D. a-Good String(递归+dfs)
-
Codeforces Round #487 (Div. 2)
-
CodeForces 1324 - Codeforces Round #627 (Div. 3)
-
Codeforces Round #649 (Div. 2)-B. Most socially-distanced subsequence(思维)
-
Codeforces Round #649 (Div. 2) C-Ehab and Prefix MEXs
-
Educational Codeforces Round 71 (Rated for Div. 2)E. XOR Guessing
-
Codeforces Round #659 (Div. 2) A. Common Prefixes(字符串,思维)
-
Codeforces Round #610 (Div. 2)