题目1045:百鸡问题
时间限制:1 秒
内存限制:32 兆
特殊判题:否
提交:3634
解决:1449
-
题目描述:
-
用小于等于n元去买100只鸡,大鸡5元/只,小鸡3元/只,还有1/3元每只的一种小鸡,分别记为x只,y只,z只。编程求解x,y,z所有可能解。
-
输入:
-
测试数据有多组,输入n。
-
输出:
-
对于每组输入,请输出x,y,z所有可行解,按照x,y,z依次增大的顺序输出。
-
样例输入:
-
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
-
来源:
- 2009年哈尔滨工业大学计算机研究生机试真题
-
-
#include<iostream> #include<iomanip> using namespace std; int main() { int n,x,y,z; while(cin>>n) { for(x=0;x<=n/5;x++) { for(y=0;y<=n/3;y++) { z=100-x-y; if(5*x+3*y+z*0.33<=double(n)) { cout<<"x="<<x<<","<<"y="<<y<<","<<"z="<<z<<endl; } } } } } /************************************************************** Problem: 1045 User: 旺仔 Language: C++ Result: Accepted Time:30 ms Memory:1520 kb ****************************************************************/