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. Hive的原生部署方式

    一.Hive的部署 1.官方文档 https://cwiki.apache.org/confluence/display/Hive/GettingStarted 2.前提条件 需要安装JDK1.7之上 ...

  2. CSS -- 盒子模型 margin 的特点

    margin在使用过程中具有如下的两个特点: 1.垂直外边距塌陷 --给子元素设置margin-top的时候,如果父元素也随着margin-top改变位置 解决方式: 给父元素设置边框 给父元素设置o ...

  3. java多线程(待完善)

    1.小型系统 // 线程完成的任务(Runnable对象)和线程对象(Thread)之间紧密相连 class A implements Runnable{ public void run(){ // ...

  4. firewalld学习-zone的使用和配置

    原文地址:http://www.excelib.com/article/290/show zone文件标签名词解释 target:目标,这个前面学生也已经给大家介绍过了,可以理解为默认行为,有四个可选 ...

  5. vs2010编译C++ 状态标志

    // CTest.cpp : 定义控制台应用程序的入口点. // #include "stdafx.h" #include <iostream> #include &l ...

  6. Linux-Power-management

    1. 低级接口1.1 内核(swsusp)软件挂起1.1.1 睡眠状态的2个控制文件1.1.2 查看当前系统的睡眠控制文件内容1.1.3 状态表(表1)1.1.4 状态的使用1.2 uswsusp用户 ...

  7. 51nod 1765 谷歌的恐龙

    一开始看到了期望吓半死..然后弱弱的写了一下式子.设∑是出去m项之后的和,∑' 是m项的和. E=(n/m)*(∑'/m)+(n/m)*((n-m)/n)*(∑'/m+∑/(n-m))+(n/m)*( ...

  8. 123.ModelForm的使用

    ModelForm 在我们的实例中,需要通过models.py中定义相关的模型字段,之后在forms.py中同样需要定义每个字段进行相应的验证,这样的话,我们会需要重复定义,这样的话,就相对比较麻烦, ...

  9. 10 Class文件结构

  10. gulp和npm等安装

    提前安装了node.js, https://nodejs.org/zh-cn/download/ 跟着提示安装就行,然后执行一下命令cdm看下版本号如下图就说明安装成功了 安装包里面集成了npm,然后 ...