• Codeforces Round #491 (Div. 2)


    Codeforces Round #491 (Div. 2)


    A. If at first you don't succeed...

    按题意判断

    #include <bits/stdc++.h>
    #define rep(i,a,b) for(int i=a;i<=b;++i)
    #define pb push_back
    #define mem(W) memset(W,0,sizeof(W))
    typedef long long ll;
    inline int read() {
        char c=getchar();int x=0,f=1;
        while(!isdigit(c)){if(f=='-')f=-1;c=getchar();}
        while(isdigit(c)){x=x*10+c-'0';c=getchar();}
        return x*f;
    }
    using namespace std;
    int n,a,b,c;
    int main() {
        scanf("%d%d%d%d",&a,&b,&c,&n);
        int p = a+b-c;
        if(a>=c&&b>=c&&n-p>=1) printf("%d
    ",n-p);
        else printf("-1
    ");
        return 0;
    }
    
    

    B. Getting an A

    排序之后,暴力修改加check...被fst。。。凉透

    #include <bits/stdc++.h>
    #define rep(i,a,b) for(int i=a;i<=b;++i)
    #define pb push_back
    #define mem(W) memset(W,0,sizeof(W))
    typedef long long ll;
    inline int read() {
        char c=getchar();int x=0,f=1;
        while(!isdigit(c)){if(f=='-')f=-1;c=getchar();}
        while(isdigit(c)){x=x*10+c-'0';c=getchar();}
        return x*f;
    }
    using namespace std;
    int n;
    int a[111];
    bool ck() {
        double x=0;
        rep(i,1,n)x+=a[i];
        x/=n;
        return (int)(x+0.5) == 5;
    }
    int main() {
        scanf("%d",&n);
        rep(i,1,n)scanf("%d",&a[i]);
        sort(a+1,a+n+1);int ans=0;
        rep(i,1,n+1) {
            if(ck()){
                printf("%d
    ",ans);
                return 0;
            }
            if(a[i]<5){
                a[i]=5;
                ++ans;
            }
        }
        return 0;
    }
    
    

    C. Candies

    每次减(frac{1}{10})的这个操作使得数减小的非常快,二分k暴力模拟即可

    #include <bits/stdc++.h>
    #define rep(i,a,b) for(int i=a;i<=b;++i)
    #define pb push_back
    #define mem(W) memset(W,0,sizeof(W))
    typedef long long ll;
    inline int read() {
        char c=getchar();int x=0,f=1;
        while(!isdigit(c)){if(f=='-')f=-1;c=getchar();}
        while(isdigit(c)){x=x*10+c-'0';c=getchar();}
        return x*f;
    }
    using namespace std;
    ll n;
    int ck(ll k) {
        ll tn=n,x,res=0;
        while(tn) {
            if(tn<k) res+=tn,tn=0;
            else tn-=k,res+=k;
    
            if(tn>=10){
                x = tn/10;
                tn -= x;
            }
        }
        return (res*2LL >= n);
    }
    int A[10000];
    int main() {
        scanf("%I64d",&n);
        ll l=1,r=n,ans,mid;
        while(l<=r){
            mid = (l+r)/2LL;
            if(ck(mid))r=mid-1,ans=mid;
            else l=mid+1;
        }
        printf("%I64d
    ",ans);
        return 0;
    }
    
    

    D. Bishwock

    直接搜索即可。。。一开始推了个假的结论打算小范围暴力,然后dp,WA了。。。无奈交了暴力的代码。。过了

    #include <bits/stdc++.h>
    #define rep(i,a,b) for(int i=a;i<=b;++i)
    #define pb push_back
    #define mem(W) memset(W,0,sizeof(W))
    typedef long long ll;
    inline int read() {
        char c=getchar();int x=0,f=1;
        while(!isdigit(c)){if(f=='-')f=-1;c=getchar();}
        while(isdigit(c)){x=x*10+c-'0';c=getchar();}
        return x*f;
    }
    using namespace std;
    int n,ans;
    char s[2][111];
    void dfs(int now,int ed,int d){
        if(now==ed+1){
            ans = max(ans,d);
            return;
        }
        if(s[0][now-1]=='0'&&s[1][now-1]=='0'&&s[0][now]=='0'){
            s[0][now-1]=s[1][now-1]=s[0][now]='X';
            dfs(now+1,ed,d+1);
            s[0][now-1]=s[1][now-1]=s[0][now]='0';
        }
        else if(s[0][now-1]=='0'&&s[1][now-1]=='0'&&s[1][now]=='0'){
            s[0][now-1]=s[1][now-1]=s[1][now]='X';
            dfs(now+1,ed,d+1);
            s[0][now-1]=s[1][now-1]=s[1][now]='0';
        }
        else if(s[0][now-1]=='0'&&s[1][now]=='0'&&s[0][now]=='0'){
            s[0][now-1]=s[1][now]=s[0][now]='X';
            dfs(now+1,ed,d+1);
            s[0][now-1]=s[1][now]=s[0][now]='0';
        }
        else if(s[1][now-1]=='0'&&s[1][now]=='0'&&s[0][now]=='0'){
            s[1][now-1]=s[1][now]=s[0][now]='X';
            dfs(now+1,ed,d+1);
            s[1][now-1]=s[1][now]=s[0][now]='0';
        }
        else dfs(now+1,ed,d);
    }
    int solve(int l,int r){
        ans=0;
        dfs(l+1,r,0);
        return ans;
    }
    int dp[111];
    int main() {
        scanf(" %s",s[0]);
        scanf(" %s",s[1]);
        n = strlen(s[0]);
        cout << solve(0,n-1) << endl;
        return 0;
    }
    
    

    E. Bus Number

    统计0~9出现的次数,按题意暴力枚举每个数分别出现多少个,这个复杂度可以接受,对于每个情况设一共有sum个数字,A[i]为数字i出现的次数,那么(frac{sum!}{A[0]!A[1]!...A[9]!})为不管前导0情况下的排列数,现在考虑如何计算有前导0的情况,把非0的数仿照上边的方法求出排列数,现在把一个0放到开头,剩余的0插空放在这sum个数之间即可,这是经典的球盒模型,球无别,盒子有别可空。把上面两个值相减就是答案。。。。欲哭无泪的手速。。。

    #include <bits/stdc++.h>
    #define rep(i,a,b) for(int i=a;i<=b;++i)
    #define pb push_back
    #define mem(W) memset(W,0,sizeof(W))
    typedef long long ll;
    inline int read() {
        char c=getchar();int x=0,f=1;
        while(!isdigit(c)){if(f=='-')f=-1;c=getchar();}
        while(isdigit(c)){x=x*10+c-'0';c=getchar();}
        return x*f;
    }
    const int N = 105;
    using namespace std;
    int n;
    char s[33];
    int p[N], notp[N], nxt[N], b[N];
    void init(){
        notp[1]=1;nxt[1]=1;
        for(int i=2;i<=20;++i) {
            if(!notp[i]) p[++p[0]]=i,nxt[i]=i;
            for(int j=1;j<=p[0]&&i*p[j]<=20;++j) {
                notp[i*p[j]] = 1;nxt[i*p[j]]=p[j];
                if(i%p[j]==0)break;
            }
        }
    }
    ll q_pow(ll a,ll b) {
        ll ans=1;
        while(b) {
            if(b&1LL) ans=(ans*a);
            a=(a*a);
            b>>=1LL;
        }
        return ans;
    }
    inline void add(int x,int f) {
        while(x!=1){
            b[nxt[x]]+=f;
            x/=nxt[x];
        }
    }
    ll cal() {
        ll ans = 1;
        rep(i,1,p[0])ans = (ans*q_pow(p[i],b[p[i]])),b[p[i]]=0;
        return ans;
    }
    ll ans=0;
    int sum=0,num[11],A[11];
    string v;
    set<string> ts;
    void solve(){v.clear();
        rep(i,0,9)rep(j,1,num[i])v+=(char)('0'+i);
        int T = 1;
        for(int i=1;i<=v.size();++i) T*=i;
        while(T--){
            cout << v <<endl;
            if(v[0]!='0')ts.insert(v);
            next_permutation(v.begin(),v.end());
        }
    }
    void dfs(int t) {
        if(t==10){
            rep(i,1,sum)add(i,1);
            rep(i,0,9){
                rep(j,1,num[i]) add(j,-1);
            }
            //solve();
            ans += cal();
            if(num[0]){
                int m = sum-num[0]+1, n = num[0]-1;
                rep(i,1,m+n-1)add(i,1);
                rep(i,1,m-1)add(i,-1);
                rep(i,1,n)add(i,-1);
                rep(i,1,sum-num[0])add(i,1);
                rep(i,1,9)rep(j,1,num[i])add(j,-1);
                ans -= cal();
            }
            return;
        }
        if(A[t]==0)dfs(t+1);
        else {
            rep(i,1,A[t]){
                num[t]+=i;
                sum+=i;
                dfs(t+1);
                num[t]-=i;
                sum-=i;
            }
        }
    }
    
    int main() {
        init();
        scanf(" %s",s);
        n=strlen(s);
        rep(i,0,n-1)++A[s[i]-'0'];
        dfs(0);
        printf("%I64d
    ",ans);
        //cout << ts.size() << endl;
        return 0;
    }
    
    
    
  • 相关阅读:
    解决VS Code调试.NET Core应用遇到的坑
    .NET Core第三方开源Web框架YOYOFx
    【干货】”首个“ .NET Core 验证码组件
    .NET Core爬坑记 1.0 项目文件
    细说ASP.NET Core与OWIN的关系
    dock基本使用
    在VS中使用TinyFox调试OWIN应用(转)
    正则表达式的匹配
    构建乘积数组
    数组中重复的数字
  • 原文地址:https://www.cnblogs.com/RRRR-wys/p/9219483.html
Copyright © 2020-2023  润新知