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. Linux 下的php,nginx,mysql的安装

    yum -y install wget make vim install gcc gcc-c++ ncurses ncurses-devel autoconf libjpeg libjpeg-deve ...

  2. Unity 生命周期

    原文翻译:            Execution Order of Event Functions            事件函数的执行顺序                        Edit ...

  3. ACM学习-POJ-1125-Stockbroker Grapevine

    菜鸟学习ACM,纪录自己成长过程中的点滴. 学习的路上,与君共勉. ACM学习-POJ-1125-Stockbroker Grapevine Stockbroker Grapevine Time Li ...

  4. linux进程间通信之管道篇

    本文是对http://www.cnblogs.com/andtt/articles/2136279.html管道一节的进一步阐释和解释 1 管道 1.1 管道简介 管道是unix系统IPC的最古老的形 ...

  5. C# winfrom 模拟ftp文件管理

    从网上找到的非常好用的模拟ftp管理代码,整理了一下,希望对需要的人有帮助 using System; using System.Collections.Generic; using System.T ...

  6. ARCGIS接口详细说明

    ArcGIS接口详细说明 目录 ArcGIS接口详细说明... 1 1.      IField接口(esriGeoDatabase)... 2 2.      IFieldEdit接口(esriGe ...

  7. android如何调用显示和隐藏系统默认的输入法(一)

    1.调用显示系统默认的输入法 方法一. InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_MET ...

  8. Java生成登陆时使用的图片验证码

    package com.ws.frame.utils; import java.awt.Color; import java.awt.Font; import java.awt.Graphics; i ...

  9. locate: can not stat () `/var/lib/mlocate/mlocate.db': No such file or directory

    安装好CentOS后,第一次进入系统使用locate命令,结果出现:locate: can not stat () `/var/lib/mlocate/mlocate.db': No such fil ...

  10. 网易云数据结构- Maximum Subsequence Sum

    题目 题目地址 思路 显然是最大子列和的进化版,那就先思考下经典的最大子列和.这也是道思维题,啥算法也没用到,全是思维技巧,真心不知道考试遇到这种题该怎么办了. 存放答案的一个类,我把它看成一个袋子, ...