BestCoder Round #62 (div.2)Clarke and food (简单贪心)
来源:互联网 发布:apache日志 400 编辑:程序博客网 时间:2024/06/18 08:14
题目链接
题意:有个背包容量是V,现在有n个物品,每个物品有一个体积,问背包最多能装多少个。
解法:先排序,从小到大选。
#include<cstdio>#include<iostream>#include<algorithm>#include<cmath>#include<set>#include<map>#include<string>#include<cstring>#include<stack>#include<queue>#include<vector>#include<limits>#include<ctime>#include<cassert>#include<cstdlib>using namespace std;#define LL long long#define pb push_back#define X first#define Y second#define cl(a,b) memset(a,b,sizeof(a))typedef pair<int,int> P;const int maxn=100005;const int inf=1<<27;#define mod 1000000007LL a[maxn];int main(){ int T; scanf("%d",&T); while(T--){ LL n,v; scanf("%lld%lld",&n,&v); for(int i=0;i<n;i++){ scanf("%lld",&a[i]); } sort(a,a+n); LL sum=0; LL ans=0; for(int i=0;i<n;i++){ sum+=a[i]; if(sum>v){ break; }ans++; } printf("%lld\n",ans); } return 0;}
0 0
- BestCoder Round #62 (div.2)Clarke and food (简单贪心)
- BestCoder Round #62 (div.2)-Clarke and food(模拟)
- BestCoder Round #62 (div.2) 1001 Clarke and food
- BestCoder Round #62 (div.2) HDU 5562 Clarke and food
- BestCoder Round #62 (div.2) Clarke and food
- BestCoder Round #62 (div.2) HDOJ5562 Clarke and food(脑洞)
- HDU 5562 Clarke and food(排序)——BestCoder Round #62(div.2)
- BestCoder Round #62 (div.2) Clarke and five-pointed star
- BestCoder Round #62 (div.2) D.Clarke and baton
- hdu5463 Clarke and minecraft(BestCoder Round #56 (div.2) )
- HDU 5463 Clarke and minecraft(贪心)——BestCoder Round #56(div.2)
- BestCoder Round #62 (div.2)-Clarke and five-pointed star(几何)
- BestCoder Round #62 (div.2)-Clarke and baton(二分搜索)
- BestCoder Round #62 (div.2)Clarke and five-pointed star(极角排序,判断五边形)
- BestCoder Round #56 (div.2)(Clarke and minecraft)
- BestCoder Round #56 (div.2)(Clarke and problem)
- BestCoder Round #56 (div.2) HDU5463 Clarke and minecraft
- hdu 5464 Clarke and problem (BestCoder Round #56 (div.2))
- management_studio 开发总结
- java_12-24-part one
- PHP程序中字符串的使用
- HDU 2151:Worm【dp】
- Matlab C混合编程
- BestCoder Round #62 (div.2)Clarke and food (简单贪心)
- App的网络性能优化实践
- 1025. 反转链表 (25)
- Dockerize Apache HAWQ [作者:陶征霖]
- 当一个线程进入一个对象的一个synchronized()方法后,其他线程是否可进入此对象的其他方法?
- 按位与二元运算符
- Objective-C:Foundation
- Python 文档风格
- 博客2