Phigros_jiu @ 2023-12-11 12:35:04
#include<iostream>
#include <algorithm>
using namespace std;
int main(){
int n,a,b,c;
cin>>n;
if(n==0)
{
cout<<"0 0 0"<<endl;
}
for(a=n/14;a>=0;a--)
{
for(b=a;b<=n;b++)
{
for(c=n/3;c>=a;c--)
{
if(7*a+4*b+3*c==n)
{
cout<<a<<" "<<b<<" "<<c<<endl;
return 0;
}
}
}
}
cout<<"-1";
return 0;
}
求解
by _IOI_THANKFUL @ 2023-12-11 13:08:00
#include<bits/stdc++.h>
using namespace std;
int n,a,b,c;
int main(){
cin>>n;
for(a=n/14;a>=0;a--){
for(b=a;b<=n;b++){
for(c=a;c<=n/3;c++){
if(7*a+4*b+3*c==n){
cout<<a<<" "<<b<<" "<<c<<endl;
return 0;
}
}
}
}
cout<<"-1";
return 0;
}
by _IOI_THANKFUL @ 2023-12-11 13:08:17
@eee
by Phigros_jiu @ 2023-12-11 13:13:49
谢谢更改(orz