penguin1025 @ 2024-03-05 17:23:15
#include <iostream>
using namespace std;
int minn(int x, int y, int z) {
if (min(x, y) < min(y, z)) {
return min(x, y);
}
return min(y, z);
}
int main() {
int n, s = 0, min = 10005, a[5];
cin >> n;
if (n < 14) {
cout << -1;
return 0;
}
for (int i = 1; i <= n / 7; i++) {
for (int j = 1; j <= n / 4; j++) {
for (int k = 1; k <= n / 3; k++) {
if (i * 7 + j * 4 + k * 3 == n ) {
s = i + j + k;
a[1] = i;
a[2] = j;
a[3] = k;
min = minn(i, j, k);
}
}
}
}
for (int i = 1; i <= 3; i++) {
cout << a[i] << " ";
}
return 0;
}
by chenbingjie @ 2024-03-21 18:52:21
直接开把代码
#include <iostream>
using namespace std;
int n;
int main(){
cin>>n;
if(n == 0){
cout<<"0 0 0"<<endl;
return 0;
}
for(int p=n/14;p>=0;p--){
for(int j=p;j<=n/4;j++){
for(int k=p;k<=n/3;k++){
if(p*7+j*4+k*3 == n){
cout<<p<<" "<<j<<" "<<k<<endl;
return 0;
}
}
}
}
cout<<"-1"<<endl;
return 0;
}
by penguin1025 @ 2024-07-10 14:22:46
@chenbingjie 谢大佬