Problem Description
As you know, Gardon trid hard for his love-letter, and now he’s spending too much time on choosing flowers for Angel.
When Gardon entered the flower shop, he was frightened and dazed by thousands kinds of flowers.
“How can I choose!” Gardon shouted out.
Finally, Gardon-- a no-EQ man decided to buy flowers as many as possible.
Can you compute how many flowers Gardon can buy at most?
Input
Input have serveral test cases. Each case has two lines. The first line contains two integers: N and M. M means how much money Gardon have. N integers following, means the prices of differnt flowers.
Output
For each case, print how many flowers Gardon can buy at most. You may firmly assume the number of each kind of flower is enough.
Sample Input
2 5
2 3
Sample Output
2
暗示、线索:[hint]Hint[/hint]
Gardon can buy 5=2+3,at most 2 flower, but he cannot buy 3 flower with 5 yuan.
###题目解析:
简单来说:首先,多组数据输入,有两行,第一行有两个整数,第二行数的个数不确定;
第一行的两个整数:
第一个数代表:有几种不同的价格的花
第二个数代表:Gardon 总共有多少钱
第二行的数是根据第一行的第一个数确定的,也就是说第二行是不同花的价格;
例如:
2 5 ———— 2代表着有2种不同价格的花;5代表着Gardon 总共有5美元
2 3 ————由于有2种不同价格的花,所以,第二行会有两个数,分别表示2种不同的花的价格,一种是2美元,另一种是3美元
求Gardon 最多可以买多少只花?
###思路分析:
说白了,就是找到价格最便宜的花,让Gardon 的钱数除以最便宜的花,取整,得出的结果就是要求的结果。
###代码如下:
#include <stdio.h>
int main()
{int n,m,min,a;while(scanf("%d %d",&n,&m )!= EOF) //多组数据输入,n为不同种花,m为Gardon 总共的钱数{min = 10000000; //这里的min是为了找最小值,所以,min的初始化应该为一个较大值while(n--) //这里的n就代表了n种价格不同的花{scanf("%d",&a); //一次输入不同价格的花的价格if(min > a) //找价格最便宜的min = a; //将价格最便宜的价格赋值给min}printf("%d\n",m/min); //最后求Gardon 最多买几朵花,求出m/min(m为Gardon 所有的钱,min为不同种类的花中价格最便宜的价格)}return 0;
}