珂爱的萌新TLE求助

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

wwhOvO @ 2020-03-11 21:50:06

感觉有用的优化都用上了啊QAQ还是只有90分。。。

请问哪里还要优化啊QAQ

#include <iostream>
#include <stdio.h>
#include <math.h>
#define DEBUG printf("aa/7=%d bb/4=%d cc/3=%d\n",aa/7,bb/4,cc/3)
#define DEBUG2 printf("a=%d b=%d c=%d\n\n",a,b,c)
#define DEBUG3 printf("aa=%d bb=%d cc=%d\n",aa,bb,cc)

using namespace std;

int n,a,b,c;

int main()
{
    //freopen("order.in","r",stdin);
    //freopen("order.out","w",stdout);
    scanf("%d",&n);
    if(n==3) {printf("0 0 1\n");return 0;}
    if(n==4) {printf("0 1 0\n");return 0;}
    if(n==7) {printf("0 1 1\n");return 0;}
    if(n%14==0)
    {
        a=b=c=(n/14);
        printf("%d %d %d\n",a,b,c);
        return 0;
    }

    for(int i=1;i<=n/3;i++)
    {
        int aa,bb,cc=i*3;
        int can=n-cc;
        for(int j=1;j<=can/4;j++)
        {
            int nans=a+b+c;
            int minn=min(min(a,b),c);
            //cout<<minn<<endl;
            bb=j*4;
            aa=n-(bb+cc);
            //DEBUG3;
            if((aa+bb+cc==n)&&(aa%7==0)&&(aa>=0))
            {
                int now=min(min(aa/7,bb/4),cc/3);
                //DEBUG;
                //if(a==0&&b==0&&c==0) {a=aa/7,b=bb/4,c=cc/3;continue;}
                if(now>=minn)
                {
                    //DEBUG;
                    //cout<<"now="<<now<<endl;
                    //cout<<minn<<endl;
                    int ans=(aa/7)+(bb/4)+(cc/3);
                    //cout<<"ans="<<ans<<" "<<"nans="<<nans<<endl;
                    //cout<<"a="<<a<<" "<<"b="<<b<<" "<<"c="<<c<<endl;
                    if(ans>=nans) {a=aa/7,b=bb/4,c=cc/3;continue;}
                    //cout<<"Get a answer:"<<"a="<<a<<" "<<"b="<<b<<" "<<"c="<<c<<endl;
                    //<<"-------------------\n";
                    if(now!=minn) a=aa/7,b=bb/4,c=cc/3;
                }
            }
        }
    }
    if(a==0&&b==0&&c==0) printf("-1\n");
    else printf("%d %d %d\n",a,b,c);
    return 0;
}

by wwhOvO @ 2020-03-11 22:01:25

@liqingyang 自己手写的min函数

int Min(int x,int y)
{
    return x<y;
}

为啥会WA掉啊QAQ


by kevin516 @ 2020-03-11 22:01:50

@BinaryTree 听123456zmy的


by kevin516 @ 2020-03-11 22:02:20

@BinaryTree ...TA返回1or0


by 1kri @ 2020-03-11 22:02:33

@BinaryTree return x<y?x:y


by wwhOvO @ 2020-03-11 22:02:48

@kevin516 所以那坨东西NOIp能不能用啊qwq


by liqingyang @ 2020-03-11 22:02:53

@BinaryTree 不是一个bool类型的返回值呀


by kevin516 @ 2020-03-11 22:02:58

@BinaryTree TA返回bool变量so是0or1


by liqingyang @ 2020-03-11 22:03:05

@BinaryTree 建议别用


by liqingyang @ 2020-03-11 22:03:25

int Min(int x,int y)
{
    return x<y?x:y;
}

by wwhOvO @ 2020-03-11 22:03:26

@kevin516 噢我是zz


上一页 | 下一页