首页
IT
登录
6mi
u
盘
搜
搜 索
IT
1045
1045
xiaoxiao
2021-03-26
25
// 1045_百鸡问题.cpp : 定义控制台应用程序的入口点。
//1045:百鸡问题
//时间限制:1 秒内存限制:32 兆特殊判题:否提交:10137解决:4453
//题目描述:
//用小于等于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 "stdafx.h"
#include "stdio.h"
#include "iostream"
#include "string.h"
#include "string"
using
namespace
std
;
int
main() {
int
n;
int
x,y,z;
while
(
cin
>>n){
for
(
int
x =
0
;x<=
100
;x++)
for
(
int
y =
0
;y<=
100
;y++){ z =
100
-x-y;
if
(
5
*x+
3
*y+
1.0
/
3
*z<=n)
cout
<<
"x="
<<x<<
","
<<
"y="
<<y<<
","
<<
"z="
<<z<<endl; } }
return
0
; }
转载请注明原文地址: https://ju.6miu.com/read-662336.html
技术
最新回复
(
0
)