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;
}