90分求助

P6188 [NOI Online #1 入门组] 文具订购

dico @ 2020-03-08 12:15:39

最后两个点WA

#include<bits/stdc++.h>
using namespace std;
int n,a,b,c,minn,maxx,A[100001],B[100001],C[100001],to;
int main()
{
    cin>>n;
    if(n%14==0)cout<<n/14<<' '<<n/14<<" "<<n/14;
    else
    {
        for(a=0;a*7<=n;a++)
            for(b=0;b*4+7*a<=n;b++)
            {
                c=n-7*a-4*b;
                if(c%3==0&&c>=0)
                    A[to]=a,B[to]=b,C[to++]=c/3;//,cout<<a<<' '<<b<<" "<<c/3<<endl;
            }
        if(to==0){cout<<-1;return 0;}
        for(int i=0;i<to;i++)
            minn=max(minn,min(A[i],min(B[i],C[i])));
        for(int i=0;i<to;i++)
            if(minn==min(A[i],min(B[i],C[i])))maxx=max(maxx,A[i]+B[i]+C[i]);
            else A[i]=-1;
        for(int i=0;i<to;i++)
            if(A[i]!=-1&&maxx==A[i]+B[i]+C[i])
            {
                cout<<A[i]<<' '<<B[i]<<' '<<C[i];
                return 0;
            }
    }
}

by yagyagyag @ 2020-03-08 13:15:05

95求助

#include<bits/stdc++.h>
using namespace std;
const int N=1e5+5;
int n;
int min(int a,int b,int c) {//三者比大小,自定义 
    return min(a,min(b,c));
}
struct Ans {
    int a,b,c;
    int sum,min;
} f[N];
bool check(int x)
{
    if (x && (f[x].a || f[x].b || f[x].c)) return 1;
    if (x==0) return 1;
    return 0;
}
int main() {
    cin>>n;
    Ans t;
    for (int i=1; i<=n; i++) {
        if (i-3>=0 && check(i-3)) {
            t=f[i-3];
            if (min(t.a,t.b,t.c+1)>f[i].min) f[i].a=t.a,f[i].b=t.b,f[i].c=t.c+1,f[i].min=min(t.a,t.b,t.c+1),f[i].sum=t.a+t.b+t.c+1;
            else if (min(t.a,t.b,t.c+1)==f[i].min && t.a+t.b+t.c+1>f[i].sum)
                f[i].a=t.a,f[i].b=t.b,f[i].c=t.c+1,f[i].min=min(t.a,t.b,t.c+1),f[i].sum=t.a+t.b+t.c+1;
        }

        if (i-4>=0 && check(i-4)) {
            t=f[i-4];
            if (min(t.a,t.b+1,t.c)>f[i].min) f[i].a=t.a,f[i].b=t.b+1,f[i].c=t.c,f[i].min=min(t.a,t.b+1,t.c),f[i].sum=t.a+t.b+1+t.c;
            else if (min(t.a,t.b+1,t.c)==f[i].min && t.a+t.b+1+t.c>f[i].sum)
                f[i].a=t.a,f[i].b=t.b+1,f[i].c=t.c,f[i].min=min(t.a,t.b+1,t.c),f[i].sum=t.a+t.b+1+t.c;
        }

        if (i-7>=0 && check(i-7)) {
            t=f[i-7];
            if (min(t.a+1,t.b,t.c)>f[i].min) f[i].a=t.a+1,f[i].b=t.b,f[i].c=t.c,f[i].min=min(t.a+1,t.b,t.c),f[i].sum=t.a+1+t.b+t.c;
            else if (min(t.a+1,t.b,t.c)==f[i].min && t.a+1+t.b+t.c>f[i].sum)
                f[i].a=t.a+1,f[i].b=t.b,f[i].c=t.c,f[i].min=min(t.a+1,t.b,t.c),f[i].sum=t.a+1+t.b+t.c;
        }
    }
    if (f[n].a==0 && f[n].b==0 && f[n].c==0) cout<<-1<<endl;
    else cout<<f[n].a<<" "<<f[n].b<<" "<<f[n].c<<endl;
    return 0;
}

上一页 |