杭电OJ题 1587 Flowers解题报告
来源:互联网 发布:中兴g180软件 编辑:程序博客网 时间:2024/05/23 02:19
Flowers
Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 1791 Accepted Submission(s): 1191
Total Submission(s): 1791 Accepted Submission(s): 1191
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?
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.
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.
You may firmly assume the number of each kind of flower is enough.
Sample Input
2 52 3
Sample Output
2Gardon can buy 5=2+3,at most 2 flower, but he cannot buy 3 flower with 5 yuan.HintHint
————————————————————————————————
最简单的贪心
/**************************** *Name:Flowers.c *Tags:ACM water ****************************/#include <stdio.h>int main(){ int n, m, money[100], i, j, t; int count, sum; while(scanf("%d%d", &n, &m) != EOF) { for(i = 0; i < n; i++) { scanf("%d", money+i); } t = money[0]; for(i = 0; i < n-1; i++) { for(j = 0; j < n-1-i; j++) {if(money[j] > money[j+1]) { t = money[j]; money[j] = money[j+1]; money[j+1] = t;} } } sum = 0; count = 0; /*for(i = 0; i < n; i++) { if(sum < m) {count++;sum += money[i]; } else {if(sum > m) { count--;}break; } }*/ while(sum < m) { count++; sum += money[0]; } if(sum > m) { count--; } printf("%d\n", count); } return 0;}
- 杭电OJ题 1587 Flowers解题报告
- 杭电OJ 1209题clock 解题报告
- 杭电OJ题 1106 排序 解题报告
- 杭电OJ 题 1209 Clock 解题报告
- 杭电OJ题 1236 排名 解题报告
- 杭电OJ题 1391 Number Steps 解题报告
- 杭电OJ题 1347 Grandpa is Famous解题报告
- 杭电OJ题 1361 Parencodings解题报告
- 杭电OJ题 1379 DNA Sorting解题报告
- 杭电OJ题 1390 Binary Numbers解题报告
- 杭电OJ题 1393 Weird Clock解题报告
- 杭电OJ题 Goldbach's Conjecture解题报告
- 杭电OJ题 1408 盐水的故事 解题报告
- 杭电OJ题 1412 {A} + {B} 解题报告
- 杭电OJ题 1444 Maya Calendar解题报告
- 杭电OJ题 1491 Octorber 21st 解题报告
- 杭电OJ题 1555 How many days?解题报告
- 杭电OJ题 1562 Guess the number解题报告
- 杭电OJ题 1562 Guess the number解题报告
- 修改当前进程访问权限代码
- MySQL 存储引擎
- Eclipse JUNO No Application Items
- PL/SQL连接64位oracle客户端
- 杭电OJ题 1587 Flowers解题报告
- windowsphone中WebBrowser中的页面按级回退功能
- C++11维基百科
- Linux环境下段错误的产生原因及调试方法小结
- Windows Phone 中WebBrowser打开新窗口
- (转)Eclipse导入包提示Setting build path has encountered a problem
- 杭电OJ题 1597 find the nth digit解题报告
- {dede:php}与自定义标签
- WP7 如何禁用WebBrowser 控件缩放和左右移动