牛客小白月赛68 ABCDE

https://ac.nowcoder.com/acm/contest/51958

这场小白挺友好的,前五题都过了差不多500人。(比赛时不舒服打一半跑了,刚自己写完了剩下的(除了F,来水一下题解hh

A-Tokitsukaze and New Operation

#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef pair<LL,LL> PII;
const LL MAXN=1e18,MINN=-1e18;
const LL N=1e6+10,M=2023;
const LL mod=998244353;
const double PI=3.1415926535;
#define endl '\n'
int main()
{
    cin.tie(0); cout.tie(0); ios::sync_with_stdio(false);
    int T=1;
    cin>>T;
    while(T--)
    {
        string s,c;
        cin>>s>>c;
        if(s.size()!=c.size()) cout<<"-1"<<endl;
        else
        {
            string ans="";
            for(int i=0;i<s.size();i++)
            {
                ans+=to_string((s[i]-'0')*(c[i]-'0'));
            }
            cout<<ans<<endl;
        }

    }
    return 0;
}

B-Tokitsukaze and Order Food Delivery

#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef pair<LL,LL> PII;
const LL MAXN=1e18,MINN=-1e18;
const LL N=1e6+10,M=2023;
const LL mod=998244353;
const double PI=3.1415926535;
#define endl '\n'
int main()
{
    cin.tie(0); cout.tie(0); ios::sync_with_stdio(false);
    int T=1;
    cin>>T;
    while(T--)
    {
        LL n,a,b;
        cin>>n>>a>>b;
        LL ans=MAXN;
        for(int i=1;i<=n;i++)
        {
            LL k,x,y;
            cin>>k>>x>>y;
            for(int j=1;j<=k;j++)
            {
                LL num;
                cin>>num;
                LL sum=0;
                if(num>=x&&num>=a) sum=max((LL)0,num-y-b);
                else if(num>=x) sum=max((LL)0,num-y);
                else if(num>=a) sum=max((LL)0,num-b);
                else sum=num;
                ans=min(ans,sum);
            }
        }
        cout<<ans<<endl;
    }
    return 0;
}

C-Tokitsukaze and Average of Substring

数据范围才5k 这么小,直接暴力循环

#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef pair<LL,LL> PII;
const LL MAXN=1e18,MINN=-1e18;
const LL N=1e6+10,M=2023;
const LL mod=998244353;
const double PI=3.1415926535;
#define endl '\n'
LL sum[N];
int main()
{
    cin.tie(0); cout.tie(0); ios::sync_with_stdio(false);
    int T=1;
    cin>>T;
    while(T--)
    {
        LL n;
        cin>>n;
        string s;
        cin>>s;
        s=" "+s;
        map<char,LL> mp;
        double maxn=0,sum=0;
        for(int i=1;i<s.size();i++)
        {
            mp.clear();
            mp[s[i]]++;
            for(int j=i+1;j<s.size();j++)
            {
                mp[s[j]]++;
                sum+=mp[s[j]]-1;
                //double ans=(double)sum/(1.0*(j-i+1));
                //printf("%.10lf\n",ans);
                maxn=max(maxn,(double)sum/(1.0*(j-i+1)));
            }
            sum=0;
        }
        printf("%.10lf\n",maxn);
    }
    return 0;
}

D-Tokitsukaze and Development Task

不难,就是烦了点,注意分界,想明白两端计数情况即可

#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef pair<LL,LL> PII;
const LL MAXN=1e18,MINN=-1e18;
const LL N=1e6+10,M=2023;
const LL mod=998244353;
const double PI=3.1415926535;
#define endl '\n'
LL a[N],res[N];
int main()
{
    cin.tie(0); cout.tie(0); ios::sync_with_stdio(false);
    int T=1;
    cin>>T;
    while(T--)
    {
        LL ans=0;
        for(int i=1;i<=4;i++)
        {
            cin>>a[i];
            //a[i]=i;
            LL sum=0;
            LL x=a[i];
            if(a[i]==10) ;
            else if(a[i]==300) sum++;
            else if(a[i]>10&&a[i]<=110)
            {
                LL num1=(x-10)/10+(x%10);
                LL num2=x/10+(10-(x%10));
                LL num3=1+(110-x)/10+(110-x)%10;
                LL num4=2+(110-x)/10+(10-(110-x)%10);
                //cout<<num1<<" "<<num2<<" "<<num3<<" "<<num4<<endl;
                sum+=min({num1,num2,num3,num4});
            }
            else if(a[i]>=110&&a[i]<=200)
            {
                LL num1=1+(x-110)/10+(x%10);
                LL num2=2+(x-110)/10+(10-(x%10));
                LL num3=2+(200-x)/10+(200-x)%10;
                LL num4=3+(200-x)/10+(10-(200-x)%10);
                //cout<<num1<<" "<<num2<<" "<<num3<<" "<<num4<<endl;
                sum+=min({num1,num2,num3,num4});
            }
            else if(a[i]>=200&&a[i]<=210)
            {
                LL num1=2+(x%10);
                LL num2=2+(10-(x%10));
                //cout<<num1<<" "<<num2<<endl;
                sum+=min({num1,num2});
            }
            else if(a[i]>=210&&a[i]<300)
            {
                LL num1=2+(x-210)/10+(x%10);
                LL num2=3+(x-210)/10+(10-(x%10));

                LL num3=1+(300-x)/10+(300-x)%10;
                LL num4=2+(300-x)/10+(10-(300-x)%10);
                //cout<<num1<<" "<<num2<<" "<<num3<<" "<<num4<<endl;
                sum+=min({num1,num2,num3,num4});
            }
            ans+=sum;
            //cout<<sum<<endl;
            //res[i]=sum;
        }
        cout<<ans<<endl;
        //for(int i=10;i<=300;i++) cout<<i<<" "<<res[i]<<endl;
    }
    return 0;
}

E-Tokitsukaze and Colorful Chessboard

二分搜索

#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef pair<LL,LL> PII;
const LL MAXN=1e18,MINN=-1e18;
const LL N=1e6+10,M=2023;
const LL mod=998244353;
const double PI=3.1415926535;
#define endl '\n'
LL n,m;
LL ans=0;
bool check(LL x)
{
    LL sum1,sum2;
    if(x%2==0)
    {
        sum1=x/2*x; //多
        sum2=x*x-sum1; //少
    }
    else
    {
        sum1=(x-1)/2*(x-1)+x;
        sum2=x*x-sum1;
    }
    if(sum1<m||sum2<n) return false;
    else return true;
}
int main()
{
    cin.tie(0); cout.tie(0); ios::sync_with_stdio(false);
    int T=1;
    cin>>T;
    while(T--)
    {
        cin>>n>>m;
        if(n>m) swap(n,m);
        LL l=1,r=1e9;
        while(l<=r)
        {
            LL mid=(l+r)/2;
            if(check(mid)==true)
            {
                ans=mid;
                r=mid-1;
            }
            else l=mid+1;
        }
        cout<<ans<<endl;
    }
    return 0;
}
posted @ 2023-03-12 17:42  高尔赛凡尔娟  阅读(10)  评论(0编辑  收藏  举报