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 ...
随机推荐
- 【try..catch..】【判断输入是否为空】【onchange事件】【onmouseover和onmouseout事件】【onmousedown和onmouseup事件】
1.try..catch.. <body><script>function myFunction(){try{ var x=document.getElementById(&q ...
- Codeforces Round #545 (Div. 2)(D. Camp Schedule)
题目链接:http://codeforces.com/contest/1138/problem/D 题目大意:给你两个字符串s1和s2(只包含0和1),对于s1中,你可以调换任意两个字符的位置.问你最 ...
- 黑马程序员_超全面的JavaWeb视频教程vedio--.ppt,.pptx,.doc,.txt,.docx列表
\JavaWeb视频教程_day1-资料源码\day01-html目录.txt;\JavaWeb视频教程_day1-资料源码\PPT\HTML.ppt;\JavaWeb视频教程_day1-资料源码\资 ...
- 前端 - jsonp 跨域ajax
jsonp 跨域ajax原理: 浏览器同源策略限制 如何解决同源策略限制: 方式一: 利用创建script块,在其中执行src属性为 远程url 异域 用函数(返回值) 的形式返回参数 方式二: jq ...
- MySql cmd下的学习笔记 —— 有关select的操作(max, min等常见函数)
先把之前建的goods表找到 找到最贵的本店价(max) 找到最便宜的本店价(min) 查出一共还有多少商品(count) 查看商品价的平均价(avg) 查看本店有多少种商品 当count(*)时 输 ...
- YOLOv1
学习资料: https://blog.paperspace.com/tag/series-yolo/ https://blog.csdn.net/u014380165/article/details/ ...
- Pytorch tutorial 之Datar Loading and Processing (1)
引自Pytorch tutorial: Data Loading and Processing Tutorial 这节主要介绍数据的读入与处理. 数据描述:人脸姿态数据集.共有69张人脸,每张人脸都有 ...
- 基于React 的前端UI开发框架 及与Electron 的结合 https://cxjs.io/
1.cxjs 基于React 的前端UI开发框架 https://cxjs.io/ coreu http://coreui.io/ 2.antd-admin ...
- python3+selenium入门02-操作火狐浏览器
使用selenium打开浏览器的时候,需要先去selenium官网下载一个对应浏览器的的driver插件.selenium下载.官网在国外可能打不开.或者可以从我网盘下载,但可能不是最新的网盘链接.将 ...
- web服务器上某一中文名文件无法访问
只需要在此目录下 convmv -f GBK -t UTF-8 --notest *.xxx 执行这个命令即可