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. IdentityServer4专题之二:OpenID介绍

    1.基于概念 OpenId是一个以用户为中心的数字身份识别框架,它具有开放.分散.自由等特性.OpenId的创建是基于这样一个概念:我们可以通过URI(或者URL网址)来识别一个网站.同样,我们也可以 ...

  2. 前端学习笔记系列一:15vscode汉化、快速复制行、网页背景图有效设置、 dl~dt~dd标签使用

    ctrl+shift+p,调出configure display language,选择en或zh,若没有则选择安装使用其它语言,则直接呼出扩展程序搜索界面,选择,然后安装,重启即可. shift+a ...

  3. C# 篇基础知识10——多线程

    1.线程的概念 单核CPU的计算机中,一个时刻只能执行一条指令,操作系统以“时间片轮转”的方式实现多个程序“同时”运行.操作系统以进程(Process)的方式运行应用程序,进程不但包括应用程序的指令流 ...

  4. centos 安装 memcached

    centos 安装 memcached 1. 安装依赖: libeventyum install libevent-devel 2. 获取最新版本wget http://memcached.org/l ...

  5. 线程与IO

    pread/pwrite 定位和读取成为原子操作

  6. P1058 选择题

    P1058 选择题 转跳点:

  7. springMVC,spring和Hibernate整合(重要)

    springMVC,spring和Hibernate整合 https://my.oschina.net/hugohxb/blog/184715 第一步:搭建一个springmvc工程,需要的jar有: ...

  8. mysql 添加索引语句

    1.PRIMARY  KEY(主键索引)        mysql>ALTER  TABLE  `table_name`  ADD  PRIMARY  KEY (  `column`  ) 2. ...

  9. Apache http 包中的常量

    org.apache.* org.apache.http.Consts public static final int CR 13 public static final int HT 9 publi ...

  10. JAVA笔记01 变量的取名

    第2章 有意义的命名2.1 介绍2.2 名副其实 变量名太随意,haha.list1.ok 这些都没啥意义2.3 避免误导 包含List等关键字.字母o与数字0等2.4 做有意义的区分 反面教材,变量 ...