博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
hdu 5562 Clarke and food(贪心)
阅读量:7075 次
发布时间:2019-06-28

本文共 1666 字,大约阅读时间需要 5 分钟。

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(1≤T≤10), the number of the test cases.For each test case: The first line contains two integers n,V(1≤n≤105,1≤V≤109). The second line contains n integers, the ith integer denotes vi(1≤vi≤109).

 

Output
For each test case, print a line with an integer which denotes the answer.

 

Sample Input
13 51 3 4

 

Sample Output
2

 

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

 

Source
 
贪心,将值从小到大排序后,一直选就可以了。
 
1 #pragma comment(linker, "/STACK:1024000000,1024000000") 2 #include
3 #include
4 #include
5 #include
6 #include
7 #include
8 #include
9 #include
10 #include
11 #include
12 #include
13 #include
14 #include
15 using namespace std;16 #define PI acos(-1.0)17 #define max(a,b) (a) > (b) ? (a) : (b)18 #define min(a,b) (a) < (b) ? (a) : (b)19 #define ll long long20 #define eps 1e-1021 #define MOD 100000000722 #define N 10000623 #define inf 1e1224 int n,v;25 int a[N];26 int dp[N];27 int dp_num[N];28 int main()29 {30 int t;31 scanf("%d",&t);32 while(t--){33 scanf("%d%d",&n,&v);34 for(int i=0;i
0){41 if(v>=a[index]){42 v-=a[index];43 index++;44 ans++;45 }else{46 break;47 }48 49 }50 printf("%d\n",ans);51 }52 return 0;53 }
View Code

 

转载地址:http://rodml.baihongyu.com/

你可能感兴趣的文章
获取文件或是文件夹的大小和占用空间
查看>>
libssh2进行远程运行LINUX命令
查看>>
Android Gson深入分析
查看>>
Android中自动跳转到系统设置界面
查看>>
树后台数据存储(採用webmethod)
查看>>
Android利用Fiddler进行网络数据抓包【怎么跟踪微信请求】
查看>>
memcached系列之二
查看>>
Atitit. 如何判断软件工程师 能力模型 程序员能力模型 项目经理能力模型...
查看>>
2016第8周五
查看>>
CSS3文本溢出显示省略号
查看>>
zookeeper系列之通信模型(转)
查看>>
.Net开源SqlServer ORM框架SqlSugar整理
查看>>
JQuery在循环中绑定事件的问题详解
查看>>
用Inno Setup来解决.NetFramework安装问题 (转载)
查看>>
使用axis调用WebService服务端
查看>>
Linux下通过受限bash创建指定权限的账号
查看>>
php:使用XHProf查找PHP性能瓶颈
查看>>
Ubuntu单用户模式(安全模式)
查看>>
Python之反射练习
查看>>
[MST] Describe Your Application Domain Using mobx-state-tree(MST) Models
查看>>