hdoj 5562 Clarke and food 【水题】
来源:互联网 发布:淘宝上二手ipad靠谱吗 编辑:程序博客网 时间:2024/05/18 13:45
Clarke and food
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 654 Accepted Submission(s): 380
Problem Description
Clarke is a patient with multiple personality disorder. One day, Clarke turned into a cook, was shopping for food.
Clarke has boughtn food. The volume of the i th food is vi . Now Clarke has a pack with volume V . He wants to carry food as much as possible. Tell him the maxmium number he can brought with this pack.
Clarke has bought
Input
The first line contains an integer T(1≤T≤10) , the number of the test cases.
For each test case:
The first line contains two integersn,V(1≤n≤105,1≤V≤109) .
The second line containsn integers, the i th integer denotes vi(1≤vi≤109) .
For each test case:
The first line contains two integers
The second line contains
Output
For each test case, print a line with an integer which denotes the answer.
Sample Input
13 51 3 4
Sample Output
2Hint: We can carry 1 and 3, the total volume of them is 5.
题意:给定n个物品和一个容量,问最多能够装多少个物品。
排序后,一直装到不能装为止。
AC代码:
#include <cstdio>#include <cstring>#include <cmath>#include <cstdlib>#include <algorithm>#include <queue>#include <stack>#include <map>#include <vector>#define INF 0x3f3f3f#define eps 1e-4#define MAXN (100000+10)#define MAXM (100000)#define Ri(a) scanf("%d", &a)#define Rl(a) scanf("%lld", &a)#define Rf(a) scanf("%lf", &a)#define Rs(a) scanf("%s", a)#define Pi(a) printf("%d\n", (a))#define Pf(a) printf("%.2lf\n", (a))#define Pl(a) printf("%lld\n", (a))#define Ps(a) printf("%s\n", (a))#define W(a) while(a--)#define CLR(a, b) memset(a, (b), sizeof(a))#define MOD 1000000007#define LL long long#define lson o<<1, l, mid#define rson o<<1|1, mid+1, r#define ll o<<1#define rr o<<1|1using namespace std;int a[MAXN];int main(){ int t; Ri(t); W(t) { int n, V; Ri(n); Ri(V); for(int i = 0; i < n; i++) Ri(a[i]); sort(a, a+n); int ans = 0; for(int i = 0; i < n; i++) { if(V >= a[i]) { ans++; V -= a[i]; } else break; } Pi(ans); } return 0;}
0 0
- hdoj 5562 Clarke and food 【水题】
- HDOJ 5562 Clarke and food
- HDOJ 5562 Clarke and food(贪心,水)
- hdoj--5562--Clarke and food(模拟)
- hdoj Clarke and food 5562 (简单题)
- hdu 5562 Clarke and food(水)
- 杭电5562之Clarke and food
- Clarke and food(HDU5562)
- BestCoder Round #62 (div.2) HDU 5562 Clarke and food
- HDU 5562 Clarke and food(模拟,看起来像背包)
- HDU5562——Clarke and food
- hdoj 5625 Clarke and chemistry
- HDU 5562 Clarke and food(排序)——BestCoder Round #62(div.2)
- BestCoder Round #62 (div.2)-Clarke and food(模拟)
- BestCoder Round #62 (div.2) 1001 Clarke and food
- BestCoder Round #62 (div.2) Clarke and food
- BestCoder Round #62 (div.2) HDOJ5562 Clarke and food(脑洞)
- HDOJ-5446 Clarke and problem(DP)
- 线段树延迟标记精讲
- LeetCode 14 : Longest Common Prefix (Java)
- 图的搜索
- Python环境下新模块的安装(httplib2)
- hdoj 反素数 2521 (打表&暴力)
- hdoj 5562 Clarke and food 【水题】
- Hint:Parameter 'in' is declared but never used in 'query_student'
- Android图片之三级缓存(着重讲内存缓存)
- XMPP
- python编码问题的另一种解决方式(vim)
- OpenCV&VS2010&Win7(64位)配置
- 内存管理中虚拟地址与物理地址转化图
- python write出现 Non-character array cannot be interpreted as character buffer.
- Android_头像裁剪上传源码与讲解