poj-3627
2015-08-25 09:55
225 查看
题意:
输入一个N和B N为牛的个数,B为高度,然后输入N头牛,为最少多少头牛加起来高度大于B
解题思路:
排序,贪心
具体代码:
View Code
输入一个N和B N为牛的个数,B为高度,然后输入N头牛,为最少多少头牛加起来高度大于B
解题思路:
排序,贪心
具体代码:
#include<iostream> #include<algorithm> #include<cstring> using namespace std; int main() { int n,b; int num[20005]; int sum=0; cin>>n>>b; for(int i=0;i<n;i++) cin>>num[i]; sort(num,num+n); int xx=n; while(sum<b) { xx--; sum+=num[xx]; } cout<<n-xx<<endl; // system("pause"); return 0; }
View Code
相关文章推荐
- poj-3438
- poj-3302
- 辽宁省赛——杨鲁斯卡尔专场-J
- 辽宁省赛——杨鲁斯卡尔专场 -F
- 临时变量作为非const的引用进行参数传递引发的编译错误
- Spark技术实战之1--KafkaWordCount
- 【HDU3038】【加权并查集】
- 临时变量作为非const的引用进行参数传递引发的编译错误
- HDU 2844+POJ 1014 +FZU 1432详解(多重背包&&二进制优化)
- POJ 3126 Prime Path (BFS)
- 揭秘谷歌网络基础设施十年演变过程
- vijos1098:合唱队形
- 5.5 运算符问题
- zzuli训练赛_05_13-K
- poj-1426(转)
- 转贴 poj分类
- 转贴 poj分类
- poj-1321
- 解决 ffmpeg yasm not found, use --disable-yasm for a crippled build
- nyoj--水池数目