其他分享
首页 > 其他分享> > Codeforces 1154 - A/B/C/D/E/F/G - (Undone)

Codeforces 1154 - A/B/C/D/E/F/G - (Undone)

作者:互联网

链接:https://codeforces.com/contest/1154


A - Restoring Three Numbers - [水]

#include<bits/stdc++.h>
using namespace std;

int a[4];
int main()
{
    cin>>a[0]>>a[1]>>a[2]>>a[3];
    sort(a,a+4);
    for(int i=0;i<=2;i++) printf("%d ",a[3]-a[i]);
}

 


B - Make Them Equal - [分类讨论]

#include<bits/stdc++.h>
using namespace std;
const int maxn=105;
int n;
int a[maxn];
bool vis[maxn];

bool check(int x,int p)
{
    for(int i=1;i<=n;i++)
    {
        if(a[i]+x==p || a[i]==p || a[i]-x==p) continue;
        return 0;
    }
    return 1;
}
int main()
{
    cin>>n;

    int cnt=0;
    for(int i=1;i<=n;i++)
    {
        cin>>a[i];
        if(!vis[a[i]]) vis[a[i]]=1, cnt++;
    }

    if(cnt==1){printf("0\n"); return 0;}

    if(cnt==2)
    {
        int min1=0, min2=0;
        for(int x=1;x<=100;x++)
        {
            if(vis[x])
            {
                if(min1==0) min1=x;
                else if(min2==0) min2=x;
                else break;
            }
        }
        int D;
        if((min2-min1)%2==0) D=(min2-min1)/2;
        else D=min2-min1;
        cout<<D<<endl;
        return 0;
    }

    int min1=0, min2=0, min3=0;
    for(int x=1;x<=100;x++)
    {
        if(vis[x])
        {
            if(min1==0) min1=x;
            else if(min2==0) min2=x;
            else if(min3==0) min3=x;
            else break;
        }
    }
    if(min3-min2==min2-min1)
    {
        int D=min3-min2;
        if(check(D,min2)) cout<<D<<endl;
        else cout<<-1<<endl;
    }
    else cout<<-1<<endl;
}

 


C - Gourmet Cat

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;

ll a,b,c;
ll run(int st)
{
    ll A=a, B=b, C=c;
    for(int i=st;i<=7;i++)
    {
        if(i==1 || i==4 || i==7)
        {
            if(A>0) A--;
            else return i-st;
        }
        else if(i==2 || i==6)
        {
            if(B>0) B--;
            else return i-st;
        }
        else if(i==3 || i==5)
        {
            if(C>0) C--;
            else return i-st;
        }
    }
    ll ans=7-st+1;
    ll num=min(min(A/3,B/2),C/2);
    ans+=num*7;
    A-=3*num, B-=2*num, C-=2*num;
    for(int i=1;;i++)
    {
        if(i==1 || i==4 || i==7)
        {
            if(A>0) A--;
            else return ans+i-1;
        }
        else if(i==2 || i==6)
        {
            if(B>0) B--;
            else return ans+i-1;
        }
        else if(i==3 || i==5)
        {
            if(C>0) C--;
            else return ans+i-1;
        }
    }
}
int main()
{
    cin>>a>>b>>c;
    ll ans=0;
    for(int st=1;st<=7;st++)
    {
        ll res=run(st);
        //printf("%d: %I64d\n",st,res);
        ans=max(ans,res);
    }
    cout<<ans<<endl;
}

 


D - Walking Robot - [贪心]

 


E - Two Teams - [线段树+链表]

 


F - Shovels Shop - [DP]

 


G - Minimum Possible LCM - (Undone)

标签:return,int,1154,ll,Codeforces,st,Undone,ans,else
来源: https://www.cnblogs.com/dilthey/p/10742353.html