(Relax ST1.19)POJ 3627 Bookshelf(贪心)
2013-11-28 22:03
411 查看
问题:已知有n个人及每个人的身高,问为了达到高度b,最少需要几个人叠罗汉。保证n个人的总身高超过b。
思路:先取身高最高的,如果不足b,再取剩下中最高的。先排序,再贪心。
思路:先取身高最高的,如果不足b,再取剩下中最高的。先排序,再贪心。
/* * POJ_3627.cpp * * Created on: 2013年11月26日 * Author: Administrator */ #include <iostream> #include <cstdio> #include <algorithm> using namespace std; const int maxn = 20005; int a[maxn]; bool cmp(int a,int b){ return a>b; } int main(){ int n,b; while(scanf("%d%d",&n,&b)!=EOF){ int i; for(i = 0 ; i < n ; ++i){ scanf("%d",&a[i]); } sort(a,a+n,cmp); int count = 0; int sum = 0; for(i = 0 ; i < n ; ++i){ sum += a[i]; count++; if(sum >= b){ break; } } printf("%d\n",count); } return 0; }
相关文章推荐
- POJ 3627 Bookshelf 贪心 水~
- POJ 3627 Bookshelf 贪心 水~
- POJ 3627 Bookshelf (贪心)
- (Relax ST1.20)POJ 3663 Costume Party(贪心+剪枝)
- poj 3627 Bookshelf(水~)
- (Relax 1.2)POJ 2586 Y2K Accounting Bug(贪心选择往往发生在极端处)
- (Relax ST1.11)POJ 2159 Ancient Cipher(判断一个字符串是否是另外一个字符串的原串)
- POJ 3627:Bookshelf
- (Relax 1.6)POJ 1328 Radar Installation(利用数据有序化进行贪心选择)
- POJ 3627:Bookshelf
- (Relax 数论1.19)POJ 3244 Difference between Triplets(找规律..//公式max(a,b,c)-min(a,b,c)=(|a-b|+|b-c|+|a-c)
- poj 3627 Bookshelf
- (Relax 贪心 1.3)POJ 1700 Crossing River
- (Relax ST1.22)POJ 3664 Election Time(两次排序的巧妙应用)
- POJ 3627 Bookshelf G++
- POJ 3627 Bookshelf
- (Relax ST1.29)POJ 3749 破译密码(将一个字符串按照一定的规则转化成另外一个字符串)
- (Relax ST1.16)POJ 3589 Number-guessing Game(求连个字符串中相同的字符有多少个和同位置&&同字符的字符个数有多少个)
- (Relax ST1.10)POJ 2027 No Brainer()
- (Relax ST1.3)POJ 1045 Bode Plot