胡景泰 @ 2020-03-08 16:28:10
有几个TLE很正常,但为什么还有几个WA?!求助
大佬们帮帮可怜的孩子吧QAQ [https://www.luogu.com.cn/record/31518967]()
#include<bits/stdc++.h>
using namespace std;
struct p
{
int a ,b ,c;
}p[1000000];
int main(){
//freopen("order.in","r",stdin);
//("order.out","w",stdout);
int n;
cin >> n;
int flag = 1;
/*if(n < 3)
{
cout << -1;
return 0;
}*/
bool pan = 0;
int i = 1 ,j = 1,k = 1;
for(;;i ++ )
{
if(7 * i + 4 * j + 3 * k > n)
{
break;
}
for(;;j ++)
{
if(7 * i + 4 * j + 3 * k > n)
{
j = 1;
break;
}
for(;;k ++)
{
if(7 * i + 4 * j + 3 * k == n)
{
pan = 1;
p[flag].a = i;
p[flag].b = j;
p[flag].c = k;
flag ++;
}
else if(7 * i + 4 * j + 3 * k > n)
{
k = 1;
break;
}
}
}
}
if(pan == 0)
{
cout << -1;
return 0;
}
int bestA ,bestB ,bestC;
for(i = 1;i <= flag;i ++)
{
if(i == 1)
{
bestA = p[i].a;
bestB = p[i].b;
bestC = p[i].c;
}
if(min(min(p[i].a,p[i].b),p[i].c) > min(bestA,min(bestB,bestC)))
{
bestA = p[i].a;
bestB = p[i].b;
bestC = p[i].c;
}
else if(min(min(p[i].a,p[i].b),p[i].c) == min(bestA,min(bestB,bestC)))
{
if(p[i].a + p[i].b + p[i].c > bestA + bestB + bestC)
{
bestA = p[i].a;
bestB = p[i].b;
bestC = p[i].c;
}
}
}
cout << bestA << " " << bestB << " " << bestC;
//fclose(stdin);
//fclose(stdout);
return 0;
}
by 胡景泰 @ 2020-03-08 16:29:29
这题怎么写可以让时间复杂度低一点啊
(我太蒟了)
by zhy_learn @ 2020-03-08 18:37:18
https://www.luogu.com.cn/blog/2020zenghaoyun/
看这个