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. UESTC_王之迷宫 2015 UESTC Training for Search Algorithm & String<Problem A>

    A - 王之迷宫 Time Limit: 3000/1000MS (Java/Others)     Memory Limit: 65535/65535KB (Java/Others) Submit  ...

  2. PKU 3667 Hotel(线段树)

    Hotel The cows are journeying north to Thunder Bay in Canada to gain cultural enrichment and enjoy a ...

  3. LeeCode-Spiral Matrix II

    Given an integer n, generate a square matrix filled with elements from 1 to n2 in spiral order. For ...

  4. Clash of Clans(COC)资源压缩解密

    Clash of Clans,简称为COC,中文名<部落冲突>,是ios平台上一款相当火爆的战斗策略类游戏,开发商是芬兰的supercell,据说日收入上百万美刀,创造了手游史上的一个神话 ...

  5. jar包和war包的区别:

    jar包就是别人已经写好的一些类,然后将这些类进行打包,你可以将这些jar包引入你的项目中,然后就可以直接使用这些jar包中的类和属性了,这些jar包一般都会放在lib目录下.  war是一个web模 ...

  6. [AngularJS系列(4)] 那伤不起的provider们啊~ (Provider, Value, Constant, Service, Factory, Decorator)(转)

    用AngularJS做项目,但凡用过什么service啊,factory啊,provider啊,开始的时候晕没晕?!晕没晕?!感觉干的事儿都差不多啊,到底用哪个啊?!别告诉我你们几个就是为了跟我炫耀兄 ...

  7. Json.Net介绍及实例

    本系列教程假设读者已经对Json有一定的了解,关于Json在这里不多说.本系列教程希望能对读者开发涉及到Json的.Net项目有一定的帮助.本系列教程是根据官方文档资料和自己项目应用汇总而成.如果觉得 ...

  8. python 3.5 之 单双三引号

    1. 单引号和双引号用法都是一样的,但是如果字符串里有相同的字符时要使用\进行转义 举例:1) print 'hello'2) print "hello"1和2,结果都是hello ...

  9. 简便数据库——ORMLite框架

    一.创建DataBase //使用 Singleton 避免產生多個實例(instance),要注意 thread safe 這邊使用雙重鎖定(Double-checked locking) 使用 T ...

  10. DedeCms 建站随笔(一)

    站名:524社区网 代码:DedeCms织梦5.7代码(UTF-8) 服务器:Linux 问题一:火车头(熊猫)采集,登录成功之后无法获取栏目列表. 原因:1.新建栏目后没有更新栏目HTML文件,并且 ...