用小于等于n元去买100只鸡,大鸡5元/只,小鸡3元/只,还有1/3元每只的一种小鸡,分别记为x只,y只,z只。编程求解x,y,z所有可能解。
输入描述:
测试数据有多组,输入n。
输出描述:
对于每组输入,请输出x,y,z所有可行解,按照x,y,z依次增大的顺序输出。
示例1
输入
40
输出
x=0,y=0,z=100
x=0,y=1,z=99
x=0,y=2,z=98
x=1,y=0,z=99
c++11
#include<iostream>
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
#include<string.h>
#include<algorithm>
#include<map>
#include<vector>
#include<queue>
using namespace std;
int main(){
#ifdef ONLINE_JUDGE
#else
freopen("1.txt", "r", stdin);
//在这个模板的同一级目录下建一个'1.txt'的文件
//然后把输入全部放进去保存,之后运行代码完全不用输入任何数据
#endif
int n=0;
while (scanf("%d",&n)!=EOF){
for(int x=0;x<=100;x++){
for(int y=0;y<=100-x;y++){
int z=100-x-y;
if(z+y*3*3+x*3*5<=3*n)
printf("x=%d,y=%d,z=%d\n",x,y,z);
}
}
}
return 0;
}