WDC之力 @ 2020-03-18 06:27:32
#include<bits/stdc++.h>
using namespace std;
int summax=0;
int commax=0;//when
bool noans=0;
inline void read(int &n){
n=0;
char c=0;
int w=0;
while (!isdigit(c)) w|=c=='-',c=getchar();
while (isdigit(c)) n=n*10+(c^48),c=getchar();
if(w) n=-n;
}
int main(){
int n,a,b,c;
//`cin>>n``````````````````````````````````````;
read(n);
for(int i=0;14*i<=n;i++){
for(int j=0;7*i+4*j<=n;j++){//
int k=(n-i*7-j*4)/3;
// cout<<i<<" "<<j<<" "<<k<<endl;
if(n==3*k+4*j+7*i&&k>=0){//
// cout<<i<<" "<<j<<" "<<k<<endl;
int tmp1=min(min(i,j),k);
if(commax<tmp1){//notice > or <
commax=tmp1;
// cout<<commax<<endl;
// cout<<i<<" "<<j<<" "<<k<<endl;
int tmp2=i+j+k;
if(summax<tmp2){
summax=tmp2;
// cout<<summax<<endl;
// cout<<i<<" "<<j<<" "<<k<<endl;
a=i;b=j;c=k;
noans=1;
}
}
// a=i;b=j;c=k;//where?
}
}
}
if(noans){//
//cout<<a<<" "<<b<<" "<<c;
printf("%d %d %d\n",a,b,c);
}else{//
//cout<<"-1";//
printf("-1\n");
}//
return 0;
}
by lndjy @ 2020-03-18 06:43:35
倒序枚举更快
by Kubic @ 2020-03-18 07:23:36
名字好评
by HyyypRtf06 @ 2020-03-18 07:26:10
@宇宙主宰 砍n然后O(
by Miraik @ 2020-03-18 07:35:26
我打表过的
by Terrific_Year @ 2020-03-18 07:39:14
打表水过
by Hexarhy @ 2020-03-18 08:42:03
@宇宙主宰 看我博客题解呀,有很多做法的。