Bookshelf
Time Limit: 1000MS   Memory Limit: 65536K
Total Submissions: 7758   Accepted: 3906

Description

Farmer John recently bought a bookshelf for cow library, but the shelf is getting filled up quite quickly, and now the only available space is at the top.

Each of the N cows (1 ≤ N ≤ 20,000) has some height of Hi (1 ≤ Hi ≤ 10,000) and a total height summed across all N cows of S. The bookshelf has a height of B (1 ≤ B ≤ S <
2,000,000,007).

To reach the top of the bookshelf taller than the tallest cow, one or more of the cows can stand on top of each other in a stack, so that their total height is the sum of each of their individual heights. This total height must be no less than the height
of the bookshelf. Since more cows than necessary in the stack can be dangerous, your job is to find the set of cows that produces a stack of the smallest number of cows possible such that the stack can reach the bookshelf.

Input

* Line 1: Two space-separated integers: N and B

* Lines 2..N+1: Line i+1 contains a single integer: Hi

Output

* Line 1: A single integer representing the size of the smallest set of cows that can reach the bookshelf.

Sample Input

6 40
6
18
11
13
19
11

Sample Output

3

大水题,给出一个数的序列,求最小的数量m,使这序列中m个数的和大于等于给定的数。

从大到小排个序。什么时候大于等于给定数值了,就输出即可。

代码:

#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
using namespace std; bool cmp(int a,int b)
{
return a>b;
} int main()
{
int N,B,i;
int height[20005];
cin>>N>>B; for(i=0;i<N;i++)
{
cin>>height[i];
}
sort(height,height+N,cmp); int ans=0;
for(i=0;i<N;i++)
{
ans += height[i];
if(ans>=B)
{
cout<<i+1<<endl;
return 0;
}
}
return 0;
}

版权声明:本文为博主原创文章,未经博主允许不得转载。

POJ 3627:Bookshelf的更多相关文章

  1. Node的关系型数据库ORM库:bookshelf

    NodeJs 关系数据库ORM库:Bookshelf.js bookshelf.js是基于knex的一个关系型数据库的ORM库.简单易用,内置了Promise的支持.这里主要罗列一些使用的例子,例子就 ...

  2. POJ 3321:Apple Tree + HDU 3887:Counting Offspring(DFS序+树状数组)

    http://poj.org/problem?id=3321 http://acm.hdu.edu.cn/showproblem.php?pid=3887 POJ 3321: 题意:给出一棵根节点为1 ...

  3. POJ 3252:Round Numbers

    POJ 3252:Round Numbers Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 10099 Accepted: 36 ...

  4. POJ 3627 Bookshelf 贪心 水~

    最近学业上堕落成渣了.得开始好好学习了. 还有呀,相家了,好久没回去啦~ 还有和那谁谁谁... 嗯,不能发表悲观言论.说好的. 如果这么点坎坷都过不去的话,那么这情感也太脆弱. ----------- ...

  5. POJ 1459:Power Network(最大流)

    http://poj.org/problem?id=1459 题意:有np个发电站,nc个消费者,m条边,边有容量限制,发电站有产能上限,消费者有需求上限问最大流量. 思路:S和发电站相连,边权是产能 ...

  6. POJ 3436:ACM Computer Factory(最大流记录路径)

    http://poj.org/problem?id=3436 题意:题意很难懂.给出P N.接下来N行代表N个机器,每一行有2*P+1个数字 第一个数代表容量,第2~P+1个数代表输入,第P+2到2* ...

  7. POJ 2195:Going Home(最小费用最大流)

    http://poj.org/problem?id=2195 题意:有一个地图里面有N个人和N个家,每走一格的花费是1,问让这N个人分别到这N个家的最小花费是多少. 思路:通过这个题目学了最小费用最大 ...

  8. POJ 3281:Dining(最大流)

    http://poj.org/problem?id=3281 题意:有n头牛,f种食物,d种饮料,每头牛有fnum种喜欢的食物,dnum种喜欢的饮料,每种食物如果给一头牛吃了,那么另一个牛就不能吃这种 ...

  9. POJ 3580:SuperMemo(Splay)

    http://poj.org/problem?id=3580 题意:有6种操作,其中有两种之前没做过,就是Revolve操作和Min操作.Revolve一开始想着一个一个删一个一个插,觉得太暴力了,后 ...

随机推荐

  1. java学习-初级入门-面向对象⑥-类与对象-静态static

    这次我们来学习静态(static) 知识点 1.静态方法只能调用静态变量 2.静态变量属于整个Class,会随着发生变化. 案例:定义一个自动增长的学生类. 题目要求: 定义一个学生类,除了姓名.性别 ...

  2. 【随缘更(gu)】牛客D4简要思路(没有题解)

    T1 当然不能枚举每个区间,于是我们考虑算贡献. 对于每个位置i,我们计算其作为区间内第一个出现ai的位置的区间总数,则有ans=sigma( i - last[i] ) * ( n - i + 1 ...

  3. 性能测试中TPS上不去的几种原因

    性能测试中TPS上不去的几种原因 什么叫TPS: TPS(Transaction Per Second):每秒事务数,指服务器在单位时间内(秒)可以处理的事务数量,一般以request/second为 ...

  4. java 牌型种数

    牌型种数 小明被劫持到X赌城,被迫与其他3人玩牌. 一副扑克牌(去掉大小王牌,共52张),均匀发给4个人,每个人13张. 这时,小明脑子里突然冒出一个问题: 如果不考虑花色,只考虑点数,也不考虑自己得 ...

  5. 初学微信小程序——配置问题(1)

    一.注册: 微信小程序账号注册:登录https://mp.weixin.qq.com  点击“立即注册”->”小程序” 注册完成后,下载微信小程序开发者工具: 依次点击:“首页”->“文档 ...

  6. Rolling Update【转】

    滚动更新是一次只更新一小部分副本,成功后,再更新更多的副本,最终完成所有副本的更新.滚动更新的最大的好处是零停机,整个更新过程始终有副本在运行,从而保证了业务的连续性. 下面我们部署三副本应用,初始镜 ...

  7. GNS3 模拟免费ARP

    R2 : conf t int f0/0 no shutdown ip add 192.168.1.254 255.255.255.0 end R1 : conf t int f0/0 no shut ...

  8. 空中网4k/5k月薪挑选大四实习生的线程题

    空中网4k/5k月薪挑选大四实习生的线程题 两年前,我们一个大四的学员去应聘空中网的实习生职位,空中网只给他出了三道线程题,拿回家做两天后再去给经理讲解,如果前两题做好了给4k月薪,第三道题也做出来的 ...

  9. R Akaike information criterion,AIC,一个越小越好的指标

    Akaike information criterion,AIC是什么?一个用来筛选模型的指标.AIC越小模型越好,通常选择AIC最小的模型.第一句话好记,第二句话就呵呵了,小编有时候就会迷惑AIC越 ...

  10. PG、GP与MySQL的特点和区别

    参考 PostgreSQL数据库 介绍:PostgreSQL是一种运行在Unix和Linux操作系统(在NT平台借助Cygnus也可以运行)平台上的免费的开放源码的关系数据库.最早是由美国加州大学伯克 ...