Clarke and food

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)

Total Submission(s): 620    Accepted Submission(s): 361

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
1
3 5
1 3 4
 
Sample Output
2 Hint:
We can carry 1 and 3, the total volume of them is 5.
#include<stdio.h>
#include<string.h>
#include<algorithm>
using namespace std;
int num[100100];
int main()
{
int t;
scanf("%d",&t);
while(t--)
{
int n,v;
memset(num,0,sizeof(num));
scanf("%d%d",&n,&v);
for(int i=0;i<n;i++)
scanf("%d",&num[i]);
sort(num,num+n);
int i;
for(i=0;i<n;i++)
{
if(v-num[i]<0)
break;
else
v-=num[i];
}
printf("%d\n",i);
}
return 0;
}

 

hdoj--5562--Clarke and food(模拟)的更多相关文章

  1. hdu 5562 Clarke and food(贪心)

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

  2. HDOJ 5402 Travelling Salesman Problem 模拟

    行数或列数为奇数就能够所有走完. 行数和列数都是偶数,能够选择空出一个(x+y)为奇数的点. 假设要空出一个(x+y)为偶数的点,则必须空出其它(x+y)为奇数的点 Travelling Salesm ...

  3. HDOJ 5414 CRB and String 模拟

    CRB and String Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) T ...

  4. HDOJ 4699 Editor 对顶栈模拟

    Editor Time Limit: 3000/2000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others) Total Subm ...

  5. HDOJ 2317. Nasty Hacks 模拟水题

    Nasty Hacks Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Tota ...

  6. 模拟+思维 HDOJ 5319 Painter

    题目传送门 /* 题意:刷墙,斜45度刷红色或蓝色,相交的成绿色,每次刷的是连续的一段,知道最终结果,问最少刷几次 模拟+思维:模拟能做,网上有更巧妙地做法,只要前一个不是一样的必然要刷一次,保证是最 ...

  7. 模拟 HDOJ 5099 Comparison of Android versions

    题目传送门 /* 题意:比较型号的大小 模拟:坑点在长度可能为5,此时设为'A' */ #include <cstdio> #include <algorithm> #incl ...

  8. 模拟 HDOJ 5095 Linearization of the kernel functions in SVM

    题目传送门 /* 题意:表达式转换 模拟:题目不难,也好理解题意,就是有坑!具体的看测试样例... */ #include <cstdio> #include <algorithm& ...

  9. 模拟 HDOJ 5387 Clock

    题目传送门 /* 模拟:这题没啥好说的,把指针转成角度处理就行了,有两个注意点:结果化简且在0~180内:小时13点以后和1以后是一样的(24小时) 模拟题伤不起!计算公式在代码内(格式:hh/120 ...

  10. 模拟 HDOJ 4552 Running Rabbits

    题目传送门 /* 模拟:看懂题意,主要是碰壁后的转向,笔误2次 */ #include <cstdio> #include <algorithm> #include <c ...

随机推荐

  1. 讲一讲java异常及自定义异常

    1.异常,说白了.两种,一种就是就是不能让代码通过编译的异常.另一种就是程序运行期间出现的异常.异常就是错误,只要出现异常,程序就不会向下运行了.就不会执行后面的代码了.这时候就可以通过显示statc ...

  2. Android 开发之集成百度地图的定位与地图展示

    app 应用中,大多数应用都具有定位功能,百度定位就成了开发人员的集成定位功能的首选,近期也在做定位功能,可是发现百度真是个大坑啊, sdk 命名更新了,相关代码却不更新,害得我花费了非常长时间来研究 ...

  3. How to Hide Zip Files Inside a Picture Without any Extra Software in Windows

    http://www.howtogeek.com/119365/how-to-hide-zip-files-inside-a-picture-without-any-extra-software/ c ...

  4. c语言运算符优先级与while循环案例

    sizeof可以获取数据类型的内存中的大小(字节) #include <stdio.h> #include <stdlib.h> // standared 标准 // inpu ...

  5. ubuntu修改顶栏颜色

    title: ubuntu修改顶栏颜色 toc: false date: 2018-09-29 19:14:01 categories: methods tags: Ubuntu 编辑shell主题的 ...

  6. MySQL日期数据类型和时间类型使用总结

    转自: http://blog.chinaunix.net/space.php?uid=11327712&do=blog&id=32416 MySQL 日期类型:日期格式.所占存储空间 ...

  7. quartz.net定时任务框架详解

    C#做定时任务:一是Timer:而是Quartz.net:本文就学习一下Quartz.net框架 Quartz.net非常的灵活,开发人员能用很少的代码就能完成“每隔一小时执行”.“每天2点执行”.“ ...

  8. HTTP的请求及响应

    前言 本文主要包括以下内容: HTTP是什么? HTTP 请求包括哪些部分? HTTP 响应包括哪些部分? 如何用Chrome开发者工具查看 HTTP 请求及请求的内容? 如何使用 curl 命令? ...

  9. FCC高级编程篇之Make a Person

    Make a Person Fill in the object constructor with the following methods below: getfirstname() getLas ...

  10. ES6 学习3 函数

    1.函数默认参数 在ES5我们给函数定义参数默认值是怎么样? function action(num) { num = num || 200 //当传入num时,num为传入的值 //当没传入参数时, ...