POJ 3627: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的更多相关文章
- Node的关系型数据库ORM库:bookshelf
NodeJs 关系数据库ORM库:Bookshelf.js bookshelf.js是基于knex的一个关系型数据库的ORM库.简单易用,内置了Promise的支持.这里主要罗列一些使用的例子,例子就 ...
- 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 ...
- POJ 3252:Round Numbers
POJ 3252:Round Numbers Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 10099 Accepted: 36 ...
- POJ 3627 Bookshelf 贪心 水~
最近学业上堕落成渣了.得开始好好学习了. 还有呀,相家了,好久没回去啦~ 还有和那谁谁谁... 嗯,不能发表悲观言论.说好的. 如果这么点坎坷都过不去的话,那么这情感也太脆弱. ----------- ...
- POJ 1459:Power Network(最大流)
http://poj.org/problem?id=1459 题意:有np个发电站,nc个消费者,m条边,边有容量限制,发电站有产能上限,消费者有需求上限问最大流量. 思路:S和发电站相连,边权是产能 ...
- POJ 3436:ACM Computer Factory(最大流记录路径)
http://poj.org/problem?id=3436 题意:题意很难懂.给出P N.接下来N行代表N个机器,每一行有2*P+1个数字 第一个数代表容量,第2~P+1个数代表输入,第P+2到2* ...
- POJ 2195:Going Home(最小费用最大流)
http://poj.org/problem?id=2195 题意:有一个地图里面有N个人和N个家,每走一格的花费是1,问让这N个人分别到这N个家的最小花费是多少. 思路:通过这个题目学了最小费用最大 ...
- POJ 3281:Dining(最大流)
http://poj.org/problem?id=3281 题意:有n头牛,f种食物,d种饮料,每头牛有fnum种喜欢的食物,dnum种喜欢的饮料,每种食物如果给一头牛吃了,那么另一个牛就不能吃这种 ...
- POJ 3580:SuperMemo(Splay)
http://poj.org/problem?id=3580 题意:有6种操作,其中有两种之前没做过,就是Revolve操作和Min操作.Revolve一开始想着一个一个删一个一个插,觉得太暴力了,后 ...
随机推荐
- Zookeeper集群搭建(单机多节点,伪集群,docker-compose集群)
Zookeeper介绍 原理简介 ZooKeeper是一个分布式的.开源的分布式应用程序协调服务.它公开了一组简单的原语,分布式应用程序可以在此基础上实现更高级别的同步.配置维护.组和命名服务.它的设 ...
- Mybatis入门(一)环境搭建
MyBatis 是一款优秀的持久层框架,它支持定制化 SQL.存储过程以及高级映射.MyBatis 避免了几乎所有的 JDBC 代码和手动设置参数以及获取结果集.MyBatis 可以使用简单的 XML ...
- C语言 Win32 获取显示设备信息
函数 BOOL EnumDisplayDevicesA( LPCSTR lpDevice, DWORD iDevNum, PDISPLAY_DEVICEA lpDisplayDevice, DWORD ...
- 094、Java中String类之直接赋值时的堆内存自动引用
01.代码如下: package TIANPAN; /** * 此处为文档注释 * * @author 田攀 微信382477247 */ public class TestDemo { public ...
- Visual c++6.0如何创建工程项目
首先,打开电脑里安装的visual C++ 6.0 ,进入其选择的主界面,如果兼容性不对,先调整一下电脑与软件的兼容性. 进入主界面之后,点击左上角的文件,然后点击新建,可以创建新的文件. 打开后弹出 ...
- mac java 装机清单
1. JDK8 2. Eclipse IDE for Enterprise Java Developers 3. maven 4. Postman 5. VS Code 6. finalshell ( ...
- 17 MySQL的小技巧
1.正则表达式的使用 ^ 在字符串开始处进行匹配 $ 在字符串末尾处进行匹配 . 匹配任意单个字符,包括换行符 [...] 匹配出括号内的任意字符 [^...] 匹配不出括号内的任意字符 a* ...
- Tornado -- 7 - 查询结果
查询结果 查询结果总结: 条件查询 多表查询
- PyCharm配置TensorFlow开发环境
Anaconda自带的Jupyter Notebook很方便,但是执行速度较慢,缺少调试环境.PyCharm与Jupyter Notebook相比,执行速度更快,而且提供了类似Matlab的调试工具, ...
- SQLyog连接报错 Error No.2058 Plugin caching_sha2_password could not be loaded
参考链接:https://blog.csdn.net/qq_22766431/article/details/80628583 win10系统更新安装Mysql8.0,连接SQLyog的时候出现下面错 ...