题目1045:百鸡问题

题目1045:百鸡问题

时间限制:1 秒

内存限制:32 兆

特殊判题:

提交:9895

解决:4344

题目描述:

    用小于等于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
#include <iostream>
#include<stdio.h>
#include<string>
#include<string.h>

using namespace std;

int main()
{
    int n;
    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(x*5*3+y*3*3+z<=n*3)
                {
                    printf("x=%d,y=%d,z=%d\n",x,y,z);
                }
            }
    }
    return 0;
}

 

posted @ 2016-08-25 11:18  多思考&&多动手  阅读(198)  评论(0编辑  收藏  举报