zoukankan      html  css  js  c++  java
  • 20200417(ABC)题解 by 马鸿儒

    A、B、C题:马鸿儒

    A题解:

    #include <bits/stdc++.h>
    using namespace std;
    int main()
    {
        ios::sync_with_stdio(0);
        long long a,b,c;
        cin>>a>>b>>c;
        if(a==b)
        {
            cout<<"YES";
            return 0;
        }
        if(c==0)
        {
            if(a==b) cout<<"YES";
            else cout<<"NO";
            return 0;
        }
        if((b-a)%c==0) 
        {
            if(b>a)
            {
                if(c<0) cout<<"NO";
                else cout<<"YES";
            }
            else 
            {
                if(c<0) cout<<"YES";
                else cout<<"NO";
            }
        }
        else cout<<"NO";    
    } 
    //分类

    B题解:

    #include <bits/stdc++.h>
    using namespace std;
    int main()
    {
        ios::sync_with_stdio(0);
        long long n,a,b,c,d;
        cin>>n>>a>>b>>c>>d;
        long long ans1=max(a+b,a+c);
        ans1=max(ans1,b+d),ans1=max(ans1,c+d);
        long long ans2=LLONG_MAX;
        ans2=min(a+b,a+c);
        ans2=min(ans2,b+d),ans2=min(ans2,c+d);
    //    cout<<ans1<<" "<<ans2<<endl;
        if(n>(ans1-ans2)) cout<<(n-(ans1-ans2))*n;
        else cout<<0;
    } 
    //找数学规律

    C题解:

    #include <bits/stdc++.h>
    using namespace std;
    char s[1000005];
    int n,k,pa[1000005],pb[1000005];
    int check(int x)
    {
        int f=0;
        for(int i=1;i<=n-x+1;i++) 
        {
            if(x-(pa[i+x-1]-pa[i-1])<=k) f=1;
            if(x-(pb[i+x-1]-pb[i-1])<=k) f=1;
        }
        return f;
    }
    int main()
    {
        ios::sync_with_stdio(0);
        scanf("%d%d%s",&n,&k,s+1);
        for(int i=1;i<=n;i++) pa[i]=pa[i-1]+(s[i]=='a'),pb[i]=pb[i-1]+(s[i]=='b');
        int l=k,r=n;
        while(r-l>1)
        {
            int mid=(l+r)>>1;
            if(check(mid)) l=mid;
            else r=mid;
        }
        if(check(r)) printf("%d",r);
        else printf("%d",l);
    } 
    //直接二分
  • 相关阅读:
    告别alert,拥抱console
    LeetCode之Max Points on a Line Total
    LeetCode之Maximum Product Subarray
    LeetCode之Reverse Words in a String
    LeetCode之Min Stack
    MySQL之系系统信息函数
    MySQL之日期时间函数
    MysqL之数值函数
    XML文件解析之JDOM解析
    XML文件解析之DOM4J解析
  • 原文地址:https://www.cnblogs.com/QLU-ACM/p/12921815.html
Copyright © 2011-2022 走看看