HDU 2124 Repair the Wall
http://acm.hdu.edu.cn/showproblem.php?pid=2124
When the typhoon came, everything is terrible. It kept blowing and raining for a long time. And what made the situation worse was that all of Kitty's walls were made of wood.
One day, Kitty found that there was a crack in the wall. The shape of the crack is
a rectangle with the size of 1×L (in inch). Luckly Kitty got N blocks and a saw(锯子) from her neighbors.
The shape of the blocks were rectangle too, and the width of all blocks were 1 inch. So, with the help of saw, Kitty could cut down some of the blocks(of course she could use it directly without cutting) and put them in the crack, and the wall may be repaired perfectly, without any gap.
Now, Kitty knew the size of each blocks, and wanted to use as fewer as possible of the blocks to repair the wall, could you help her ?
Each test case contains two lines.
In the first line, there are two integers L(0<L<1000000000) and N(0<=N<600) which
mentioned above.
In the second line, there are N positive integers. The ith integer Ai(0<Ai<1000000000 ) means that the ith block has the size of 1×Ai (in inch).
If Kitty could not repair the wall, just print "impossible" instead.
#include <bits/stdc++.h>
using namespace std; int L, n;
int len[610]; bool cmp(int x, int y) {
return x > y;
} int main() {
while(~scanf("%d%d", &L, &n)) {
int sum = 0, cnt = 0;
for(int i = 1; i <= n; i ++)
scanf("%d", &len[i]); sort(len + 1, len + 1 + n, cmp);
while(sum < L && cnt <= n) {
sum += len[cnt + 1];
cnt ++;
}
if(cnt <= n)
printf("%d\n", cnt);
else
printf("impossible\n");
}
return 0;
}
HDU 2124 Repair the Wall的更多相关文章
- --hdu 2124 Repair the Wall(贪心)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2124 Ac code : #include<stdio.h> #include<st ...
- 杭电 2124 Repair the Wall(贪心)
Description Long time ago , Kitty lived in a small village. The air was fresh and the scenery was ve ...
- 简单贪心) Repair the Wall hdu2124
Repair the Wall http://acm.hdu.edu.cn/showproblem.php?pid=2124 Time Limit: 5000/1000 MS (Java/Others ...
- HDU2124 Repair the Wall(贪心)
Problem Description Long time ago , Kitty lived in a small village. The air was fresh and the scener ...
- hdu 3669 Cross the Wall(斜率优化DP)
题目连接:hdu 3669 Cross the Wall 题意: 现在有一面无限大的墙,现在有n个人,每个人都能看成一个矩形,宽是w,高是h,现在这n个人要通过这面墙,现在只能让你挖k个洞,每个洞不能 ...
- Repair the Wall
问题 : Repair the Wall 时间限制: 1 Sec 内存限制: 128 MB 题目描述 Long time ago , Kitty lived in a small village. ...
- Repair the Wall (贪心)
Long time ago , Kitty lived in a small village. The air was fresh and the scenery was very beautiful ...
- hdu 1543 Paint the Wall
http://acm.hdu.edu.cn/showproblem.php?pid=1543 #include <cstdio> #include <cstring> #inc ...
- HDU 4391 Paint The Wall(分块+延迟标记)
Paint The Wall Time Limit: 20000/10000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) ...
随机推荐
- 大数据学习--day10(继承-权限-super-final-多态-组合)
继承-权限-super-final-多态-组合 权限修饰符 内容 public protected default(不写就是它) ...
- django配置虚拟环境-1
目录 安装python 使用venv虚拟环境 使用Virtualenv虚拟环境 ### Windows安装 方案一 方案二 Linux安装 其他命令 安装django 安装python https:/ ...
- A1092
可输入内容为0-9,a-z,A-Z. 输入: 第一行输入任意字符串: 第二行输入期望字符串. 输出: 如果第一行包含了所有期望字符串,输出yes和多余字符个数: 如果第一行不能完全包含期望字符串,输出 ...
- MySQL入门第三天(上)——函数与视图
一.MySQL函数 同样的,完整的函数可以参照开源中国的手册:http://tool.oschina.net/apidocs/apidoc?api=mysql-5.1-zh 1.字符函数 CONCAT ...
- nmap教程(下)
九.脚本引擎 脚本文件存放在/usr/share/nmap/scripts目录下 SCRIPT SCAN: -sC: equivalent to --script=default #启用默认类脚本 - ...
- Eclipse安装Java Class反编译插件
第一步:没有安装之前 第二步:从Eclipse Marketplace里,安装反编译插件jadclipse. 第三步:安装反编译插件之后,多了一个查看器,把"类反编译查看器"设置为 ...
- 青岛Uber司机奖励政策(8月31号~9月6号)
本周的奖励规则如下,请各位司机朋友按照自己的情况查询. 人民优步(People’s Uber) 滴滴快车单单2.5倍,注册地址:http://www.udache.com/如何注册Uber司机(全国版 ...
- Habse中Rowkey的设计原则——通俗易懂篇
Hbase的Rowkey设计原则 一. Hbase介绍 HBase -> Hadoop Database,HBase是Apache的Hadoop项目的子项目.HBase不同于一般的关系数据库,它 ...
- 开发发布npm module包
开发发布npm module包 问题 在项目开发过程中,每当进入一个新的业务项目,从零开始搭建一套前端项目结构是一件让人头疼的事情,就要重新复制一个上一个项目的前端框架和组件代码库.其中很多功能的模块 ...
- hdu1789 Doing Homework again(贪心+排序)
Doing Homework again Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Oth ...