杭电5562之Clarke and food
来源:互联网 发布:java工程师年龄要求 编辑:程序博客网 时间:2024/06/11 06:34
Description
Clarke is a patient with multiple personality disorder. One day, Clarke turned into a cook, was shopping for food.
Clarke has bought food. The volume of the th food is . Now Clarke has a pack with volume . He wants to carry food as much as possible. Tell him the maxmium number he can brought with this pack.
Clarke has bought
Input
The first line contains an integer , the number of the test cases.
For each test case:
The first line contains two integers .
The second line contains integers, the th integer denotes .
For each test case:
The first line contains two integers
The second line contains
Output
For each test case, print a line with an integer which denotes the answer.
Sample Input
13 51 3 4
Sample Output
2Hint: We can carry 1 and 3, the total volume of them is 5.
题意:输入n件食物的体积,和背包总体积,问最多能带多少件食物
分析:sort快速排序
AC代码如下:
#include "iostream"#include<algorithm>using namespace std;int main(int argc, char* argv[]){ _int64 N,i,n; _int64 m,sum; _int64 a[100001]; scanf("%d",&N); while(N--) { sum=0; scanf("%I64d%I64d",&n,&m); for (i=0;i<n;i++) { scanf("%I64d",&a[i]); } sort(a,a+n); for(i=0;i<n;i++) { sum+=a[i]; if (sum>=m) { break; } } printf("%I64d\n",i); } return 0;}
0 0
- 杭电5562之Clarke and food
- HDOJ 5562 Clarke and food
- HDOJ 5562 Clarke and food(贪心,水)
- hdu 5562 Clarke and food(水)
- hdoj--5562--Clarke and food(模拟)
- hdoj 5562 Clarke and food 【水题】
- Clarke and food(HDU5562)
- BestCoder Round #62 (div.2) HDU 5562 Clarke and food
- HDU 5562 Clarke and food(模拟,看起来像背包)
- hdoj Clarke and food 5562 (简单题)
- 杭电5625 Clarke and chemistry
- HDU5562——Clarke and food
- HDU 5562 Clarke and food(排序)——BestCoder Round #62(div.2)
- 杭电hdu 5626 Clarke and points【思维】
- 杭电 hdu 5625 Clarke and chemistry【水题】
- BestCoder Round #62 (div.2)-Clarke and food(模拟)
- BestCoder Round #62 (div.2) 1001 Clarke and food
- BestCoder Round #62 (div.2) Clarke and food
- Android 获取设备常用信息 (app版本信息 签名信息)
- Netty解决半包(TCP粘包/拆包导致)读写问题
- fontspider--字蛛的使用
- 大话设计模式13----建造者模式
- 【bzoj3611】 大工程
- 杭电5562之Clarke and food
- 非空子集个数
- wireshark捕获/过滤指定ip地址数据包
- constantize()函数
- Graham求凸包
- POJ 3450 Corporate Identity(kmp求多个字符串的最长公共子串)
- [HDU 2222] Keywords Search [AC自动机]
- 剑指offer 37题 【时间空间效率的平衡】两个链表的第一个公共结点
- 二、词法结构