Repair the Wall
问题 : Repair the Wall
时间限制: 1 Sec 内存限制: 128 MB
题目描述
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.
输入
The problem contains many test cases, please process to the end of file( EOF ).
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).
输出
For each test case , print an integer which represents the minimal number of blocks are needed.
If Kitty could not repair the wall, just print "impossible" instead.
样例输入
2 2 12 11 14 3 27 11 4 109 5 38 15 6 21 32 5 3 1 1 1
样例输出
1 1 5 impossible
解题思路
水题,直接从大到小往上补就可以了。
#include <stdio.h>
#include <algorithm>
using namespace std;
int main()
{
int l, n, i, s[666];
while (~scanf("%d%d", &l, &n))
{
for (int i = 0; i < n; i++)
scanf("%d", &s[i]);
sort(s, s + n);
for (i = n - 1; i >= 0 && l > 0; i--)
l -= s[i];
if (l > 0)
puts("impossible");
else printf("%d\n", n - i - 1);
}
return 0;
}Repair the Wall的更多相关文章
- HDU2124 Repair the Wall(贪心)
Problem Description Long time ago , Kitty lived in a small village. The air was fresh and the scener ...
- 简单贪心) Repair the Wall hdu2124
Repair the Wall http://acm.hdu.edu.cn/showproblem.php?pid=2124 Time Limit: 5000/1000 MS (Java/Others ...
- Repair the Wall (贪心)
Long time ago , Kitty lived in a small village. The air was fresh and the scenery was very beautiful ...
- HDU 2124 Repair the Wall
http://acm.hdu.edu.cn/showproblem.php?pid=2124 Problem Description Long time ago , Kitty lived in a ...
- 杭电 2124 Repair the Wall(贪心)
Description Long time ago , Kitty lived in a small village. The air was fresh and the scenery was ve ...
- --hdu 2124 Repair the Wall(贪心)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2124 Ac code : #include<stdio.h> #include<st ...
- hdu_2124 Flying to the Mars & hdu_1800 Repair the Wall 贪心水题
hdu_1800 简单排一下序,从大开始把比他小的都访问一遍,ans++: #include <iostream> #include <stdio.h> #include &l ...
- TJU Problem 1090 City hall
注:对于每一横行的数据读取,一定小心不要用int型,而应该是char型或string型. 原题: 1090. City hall Time Limit: 1.0 Seconds Memory ...
- [poj1113][Wall] (水平序+graham算法 求凸包)
Description Once upon a time there was a greedy King who ordered his chief Architect to build a wall ...
随机推荐
- 安装Vmware并破解
1. 先下载Vmware安装包 链接:http://pan.baidu.com/s/1hsjCKgk 密码:c1o6 2. 解压缩 3. 运行VMware-workstation-full-10.0. ...
- 【blog】SpringBoot聚合项目打包问题
在需要打包的模块的pom中,必须加上如下配置 <build> <plugins> <plugin> <groupId>org.springframewo ...
- mysql 原理 ~ DDL之在线DDL
一 简介:今天来DDL的变革二 DDL演化方式: 1 copy table : 1 创建临时表2 copy数据到临时表 3 rename进行交换 缺点 1 阻塞事务 2占用磁盘空间 2 inpla ...
- Css - 三大特性
css - 三大特性 1.层叠性 如果通过两个相同选择器设置了同一个元素的某个相同的css属性,按照css相同属性的出现顺序,后面的样式会覆盖前面的样式 2.继承性 祖先元素的关于文本的样式会遗传给后 ...
- Mysql多实例安装笔记
参考: 系统:KaliLinux (x86_64) 软件下载 1.下载地址: 2.选择5.6版本 安装 1.准备文件和目录 tar -zxvf mysql-5.6.40-linux-glibc2.12 ...
- google 开源项目阅读计划
1. glog 2. gflags 3. carto 4. ...
- drand48 等 随机数生成函数
参考: http://www.man7.org/linux/man-pages/man3/drand48.3.html drand48 返回服从均匀分布的·[0.0, 1.0) 之间的 double ...
- Aurelius vs mORMot vs EntityDAC Delphi 的 ORM框架
Aurelius vs mORMot vs EntityDAC Delphi 的 ORM框架: http://www.tmssoftware.com/site/aurelius.asp#produ ...
- C++、VC++、MFC网页自动注册、登陆、发帖、留言,QQ注册、QQ申请器源码、注册邮箱源码、自动发帖源码
C++.VC++.MFC网页自动注册.登陆.发帖.留言,QQ注册.QQ申请器源码.注册邮箱源码.自动发帖源码 参考资料: 自动登录yahoo邮箱http://blog.csdn.net/suisu ...
- python3之模块SMTP协议客户端与email邮件MIME对象
转载自https://www.cnblogs.com/zhangxinqi/p/9113859.html 阅读目录 1.smtplib模块的常用类与方法 2.处理邮件MIME 3.实例 (1)使用HT ...