数学、C语言问题(ACM竞赛题)火车上列车员卖鸡腿,一共来两次,第一次A元可以买到B个鸡腿,第二次C元可以买到D个,你有M元,最多能买几个鸡腿?比如,你有5元,列车员第一次来卖3元3个,第二次来4
来源:学生作业帮助网 编辑:作业帮 时间:2024/11/28 06:25:49
数学、C语言问题(ACM竞赛题)火车上列车员卖鸡腿,一共来两次,第一次A元可以买到B个鸡腿,第二次C元可以买到D个,你有M元,最多能买几个鸡腿?比如,你有5元,列车员第一次来卖3元3个,第二次来4
数学、C语言问题(ACM竞赛题)
火车上列车员卖鸡腿,一共来两次,第一次A元可以买到B个鸡腿,第二次C元可以买到D个,你有M元,最多能买几个鸡腿?
比如,你有5元,列车员第一次来卖3元3个,第二次来4元1个,你可以第一次用3元买到3个;你有3元,他第一次卖1元2个,第二次2元5个,你可以第一次用1元买两个,第二次用2元买5个,一共7个.
求详细解答.不会C语言的只要吧计算过程写出来就可以了,会C语言的最好帮忙编一下,谢谢!
原题:
Almost everybody have ever taken the train,but have you taken
a long-distance train? There are some salesmen on the long-distance
train saling their food or souvenirs,and MouGe is one of them.
Suppose you were on a train , and now MouGe comes again with some
chicken legs, he will pass through your seat twice,and each time
the price he sales his chicken legs is different. When MouGe come
,the price is A yuan for B chicken leg(s) and when he goes it is
C yuan for D chicken leg(s).You have M yuan,how many chicken legs
can you buy most?(Suppose MouGe has infinite chicken legs)
Input
The first line contains an integer T, which indicates the number of
test cases.Each test case contains an integer M(0
数学、C语言问题(ACM竞赛题)火车上列车员卖鸡腿,一共来两次,第一次A元可以买到B个鸡腿,第二次C元可以买到D个,你有M元,最多能买几个鸡腿?比如,你有5元,列车员第一次来卖3元3个,第二次来4
不需要算单价:
E=A; A便宜不动
Z=C;
if(A>=C)
{E=C;
Z=A;
L=D;
D=B;
B=L;
} C便宜,AC互换,B,D也互换.
E=M/E; 算出最多要算几次(都买便宜价格不会超出上限,涵盖所有情况)
for(i=0,F=0;iF) F=G;
}