蒟蒻求助

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

KLNG7 @ 2020-03-08 09:36:07

这个代码只有55分。。请各位大佬看看问题出在哪里

#include<bits/stdc++.h>
using namespace std;
int n,minn,sum,a,b,c;
bool flag;
int main()
{
    //freopen("order.in","r",stdin);
    //freopen("order.out","w",stdout);
    cin>>n;
    minn=sum=-1;
    flag=0;
    for(int i=0;i<=n/7;i++)
    {
        for(int j=0;j<=n/4;j++)
        {
            int k=(n-i*7-j*4)/3;
            if((n-i*7-j*4)%3==0)
            {
                flag=1;
                int x=min(i,min(j,k));
                if(x>minn)
                {
                    a=i;
                    b=j;
                    c=k;
                    minn=x;
                }
                else if(x==minn)
                {
                    if(i+j+k>sum)
                    {
                        a=i;
                        b=j;
                        c=k;
                        sum=i+j+k;
                    }
                }
            }
        }
    }
    if(flag==0) 
    {
        cout<<-1;
        return 0;
    }
    else
    {
        cout<<a<<" "<<b<<" "<<c;
    }
    return 0;
}

by lndjy @ 2020-03-08 09:37:37

看我题解去,顺便点个赞


|