Problem Description
Clarke is a patient with multiple personality disorder. One day, Clarke turned into a cook, was shopping for food.
Clarke has bought n food. The volume of the ith 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.
Input
The first line contains an integer T(≤T≤), the number of the test cases.
For each test case:
The first line contains two integers n,V(≤n≤,≤V≤).
The second line contains n integers, the ith integer denotes vi(≤vi≤).
Output
For each test case, print a line with an integer which denotes the answer.
Sample Input

Sample Output

 Hint:
We can carry 1 and 3, the total volume of them is 5.

 
Source
 
贪心,将值从小到大排序后,一直选就可以了。
 
 #pragma comment(linker, "/STACK:1024000000,1024000000")
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<math.h>
#include<algorithm>
#include<queue>
#include<set>
#include<bitset>
#include<map>
#include<vector>
#include<stdlib.h>
#include <stack>
using namespace std;
#define PI acos(-1.0)
#define max(a,b) (a) > (b) ? (a) : (b)
#define min(a,b) (a) < (b) ? (a) : (b)
#define ll long long
#define eps 1e-10
#define MOD 1000000007
#define N 100006
#define inf 1e12
int n,v;
int a[N];
int dp[N];
int dp_num[N];
int main()
{
int t;
scanf("%d",&t);
while(t--){
scanf("%d%d",&n,&v);
for(int i=;i<n;i++){
scanf("%d",&a[i]);
}
sort(a,a+n);
int ans=;
int index=;
while(v>){
if(v>=a[index]){
v-=a[index];
index++;
ans++;
}else{
break;
} }
printf("%d\n",ans);
}
return ;
}

hdu 5562 Clarke and food(贪心)的更多相关文章

  1. HDU 5628 Clarke and math——卷积,dp,组合

    HDU 5628 Clarke and math 本文属于一个总结了一堆做法的玩意...... 题目 简单的一个式子:给定$n,k,f(i)$,求 然后数据范围不重要,重要的是如何优化这个做法. 这个 ...

  2. hdu 4825 Xor Sum(trie+贪心)

    hdu 4825 Xor Sum(trie+贪心) 刚刚补了前天的CF的D题再做这题感觉轻松了许多.简直一个模子啊...跑树上异或x最大值.贪心地让某位的值与x对应位的值不同即可. #include ...

  3. hdu 5463 Clarke and minecraft(贪心)

    Problem Description Clarke is a patient with multiple personality disorder. One day, Clarke turned i ...

  4. HDU 5627 Clarke and MST &意义下最大生成树 贪心

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5627 题意:Bestcoder的一道题,让你求&意义下的最大生成树. 解法: 贪心,我们从高位 ...

  5. HDU 5813 Elegant Construction (贪心)

    Elegant Construction 题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5813 Description Being an ACMer ...

  6. HDU 5802 Windows 10 (贪心+dfs)

    Windows 10 题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5802 Description Long long ago, there was ...

  7. hdu 5565 Clarke and baton 二分

    Clarke and baton Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php? ...

  8. hdu 5563 Clarke and five-pointed star 水题

    Clarke and five-pointed star Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/show ...

  9. HDU 5500 Reorder the Books 贪心

    Reorder the Books Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php? ...

随机推荐

  1. Jquery ui datepicker 设置日期范围,如只能隔3天

    最近的后台项目前端使用了jquery ui 日历控件自然就使用了jquery ui 的   datepicker 后台数据比较好大,一般是千万级的和百万级的关联,查询会很慢,所以后加想多加些过滤条件, ...

  2. linux C连接mysql

    linux 环境下C语言连接数据库首先要配置环境 1,确定你的linux下安装mysql我们可以做个测试. 打开你的终端,在终端下输入:service mysqld status [root@bogo ...

  3. 【特殊的图+DP】【11月校赛】大家一起玩游戏

    大家一起玩游戏 Time Limit : 2000/1000ms (Java/Other)   Memory Limit : 65536/32768K (Java/Other) Total Submi ...

  4. 用户"IIS APPPOOL\xxxxxxxx"登录失败解决方案

    Server Error in '/' Application.-------------------------------------------------------------------- ...

  5. JQ动画,背景透明度

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...

  6. 检查DISPLAY设置时Xlib出现No protocol specified错误

    退出到root用户,执行xhost +命令后,再次切换到Oralce用户,执行runInstaller命令,错误消失

  7. AUL使用初记

    案例:部门有一个数据库因为机器无故重启,无法启动,初步判断是系统表空间出问题了.尝试过各种不同手段,均无法修复.后来发现上面只有一个用户的数据,遂想到直接通过AUL工具从数据文件中抽取出整个库. 准备 ...

  8. HDU 5805 - NanoApe Loves Sequence (BestCoder Round #86)

    先找相邻差值的最大,第二大,第三大 删去端点会减少一个值, 删去其余点会减少两个值,新增一个值,所以新增和现存的最大的值比较一下取最大即可 #include <iostream> #inc ...

  9. W - stl 的 优先队列 Ⅲ

    Description In a speech contest, when a contestant finishes his speech, the judges will then grade h ...

  10. linux学习笔记之零散笔记。

    部分知识,不足以成为完整博文.但又不能随意抛弃. 1,文件名建议字符集:字母+数字+ ./-/_   尽量不要使用其他符号.因为特殊符号在很多功能中已经被占用. 2,系统调用通常提供最小接口(最简易) ...