[比赛] Codeforces Round #538 (Div. 2) solution (贪心,数学其他,二分,线段树)

Posted si-rui-yang

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了[比赛] Codeforces Round #538 (Div. 2) solution (贪心,数学其他,二分,线段树)相关的知识,希望对你有一定的参考价值。

已经写了100篇题解啦!

link

solution pdf

技术图片
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
using namespace std;
inline int read(){
    int f=1,ans=0;char c;
    while(c<0||c>9){if(c==-)f=-1;c=getchar();}
    while(c>=0&&c<=9){ans=ans*10+c-0;c=getchar();}
    return ans*f;
}
int x,y,z,a,b,c,ans;
int main(){
    x=read(),y=read(),z=read(),a=read(),b=read(),c=read();
    ans=a+b+c;
    if(a<x){printf("NO");return 0;}
    ans-=x;
    a-=x;
    if(a+b<y){printf("NO");return 0;}
    ans-=y;
    if(ans<z){printf("NO");return 0;}
    else{printf("YES");return 0;}
}
A
技术图片
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#define int long long
using namespace std;
inline int read(){
    int f=1,ans=0;char c;
    while(c<0||c>9){if(c==-)f=-1;c=getchar();}
    while(c>=0&&c<=9){ans=ans*10+c-0;c=getchar();}
    return ans*f;
}
const int N=200001;
int n,m,k;
struct node{
    int val,id;
}a[N];
bool cmp(node x1,node x2){return x1.val>x2.val;}
int s[N],ans;
signed main(){
    n=read(),m=read(),k=read();
    for(int i=1;i<=n;i++) a[i].val=read(),a[i].id=i;
    sort(a+1,a+n+1,cmp);
    for(int i=1;i<=m*k;i++) s[++s[0]]=a[i].id,ans+=a[i].val;
    printf("%lld
",ans);sort(s+1,s+s[0]+1);
    for(int i=1;i<k;i++) printf("%lld ",s[i*m]);
}
B
技术图片
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<climits>
#define int long long
using namespace std;
inline int read(){
    int f=1,ans=0;char c;
    while(c<0||c>9){if(c==-)f=-1;c=getchar();}
    while(c>=0&&c<=9){ans=ans*10+c-0;c=getchar();}
    return ans*f;
}
const int MAXN=1000001;
int n,k,num[MAXN],prime[MAXN],cnt,minn=LLONG_MAX;
signed main(){
    n=read(),k=read();
    for(int i=2;i<=sqrt(k);i++){
        if(k%i==0){
            prime[++cnt]=i;
            num[cnt]=1;k/=i;
            while(k%i==0){k/=i;num[cnt]++;}
        }
    }if(k>1){prime[++cnt]=k;num[cnt]=1;}
    for(int i=1;i<=cnt;i++){
        int N=n,sum=0;
        while(N) sum+=(N/prime[i]),N/=prime[i];
        sum/=num[i];
        minn=min(minn,sum);
    }printf("%lld
",minn);
}
C
技术图片
 #include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
using namespace std;
inline int read(){
    int f=1,ans=0;char c;
    while(c<0||c>9){if(c==-)f=-1;c=getchar();}
    while(c>=0&&c<=9){ans=ans*10+c-0;c=getchar();}
    return ans*f;
}
const int MAXN=5001;
int f[MAXN][MAXN],n,col[MAXN];
int main(){
    n=read();
    for(int i=1;i<=n;i++) col[i]=read();
    memset(f,127/3,sizeof(f));
    for(int i=1;i<=n;i++) f[i][i]=0;
    for(int len=2;len<=n;len++){
        for(int i=1;i+len-1<=n;i++){
            int j=i+len-1;
            if(col[i]==col[j]) f[i][j]=min(f[i][j],f[i+1][j-1]+1);
            if(col[i]==col[i+1]) f[i][j]=min(f[i][j],f[i+1][j]);
            else f[i][j]=min(f[i][j],f[i+1][j]+1);
            if(col[j]==col[j-1]) f[i][j]=min(f[i][j],f[i][j-1]);
            else f[i][j]=min(f[i][j],f[i][j-1]+1);
        }
    }printf("%d
",f[1][n]);
}
D
技术图片
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<climits>
using namespace std;
inline int read(){
    int f=1,ans=0;char c;
    while(c<0||c>9){if(c==-)f=-1;c=getchar();}
    while(c>=0&&c<=9){ans=ans*10+c-0;c=getchar();}
    return ans*f;
}
int ask1(int x){
    printf("? %d
",x);fflush(stdout);
    int opt=read();
    return opt;
}
int ask2(int x){
    printf("> %d
",x);fflush(stdout);
    int num=read();
    return num; 
}
int qmax(){
    int l=0,r=1000000000,maxn=-INT_MAX;
    while(l<=r){
        int mid=(l+r)>>1;
        if(ask2(mid))maxn=max(maxn,mid),l=mid+1;
        else r=mid-1;
    }return maxn+1;
}int n,d,a[301];
int gcd(int a,int b){
    if(b==0) return a;
    return gcd(b,a%b);
}int maxn;
signed main(){
    n=read();
    maxn=qmax();
    for(int i=1;i<=30;i++){
        int s=(rand()*rand())%n+1;
        a[++a[0]]=ask1(s);
    }sort(a+1,a+31);
    d=maxn-a[1];
    for(int i=1;i<=29;i++) d=gcd(d,a[i+1]-a[1]);
    printf("! %d %d
",maxn-d*(n-1),d);fflush(stdout);
    return 0;
}
E

 

以上是关于[比赛] Codeforces Round #538 (Div. 2) solution (贪心,数学其他,二分,线段树)的主要内容,如果未能解决你的问题,请参考以下文章

cf比赛记录Codeforces Round #601 (Div. 2)

2020.5.28 Educational Codeforces Round 88 比赛记录

2020.5.28 Educational Codeforces Round 88 比赛记录

cf比赛记录Codeforces Round #600 (Div. 2)

codeforces比赛题解#869 CF Round #439 (Div.2)

cf比赛记录Codeforces Round #606 (Div. 2, based on Technocup 2020 Elimination Round 4)