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 ...
随机推荐
- CSS 模块的侦测
CSS 的规格发展太快,新的模块层出不穷.不同浏览器的不同版本,对 CSS 模块的支持情况都不一样.有时候,需要知道当前浏览器是否支持某个模块,这就叫做“CSS模块的侦测”. 一个比较普遍适用的方法是 ...
- Oracle Audit 审计功能的认识与使用
1.Audit的概念 Audit是监视和记录用户对数据库进行的操作,以供DBA进行问题分析.利用Audit功能,可以完成以下任务: 监视和收集特定数据库活动的数据.例如管理员能够审计哪些表被更新,在某 ...
- ActiveMQ 动态网络链接
ActiveMQ的broker-broker方式有两种,一种 静态连接一种是动态连接,一般使用静态连接,动态连接了解就好,没有过多的去测试. 1. 多播协议multicast ActiveMQ使用Mu ...
- C++以const 作为返回值类型的意义
const rational operator*(const rational& lhs, const rational& rhs); 很多程序员第一眼看到它会纳闷:为什么operat ...
- CF1095E Almost Regular Bracket Sequence
题目地址:CF1095E Almost Regular Bracket Sequence 真的是尬,Div.3都没AK,难受QWQ 就死在这道水题上(水题都切不了,我太菜了) 看了题解,发现题解有错, ...
- python目标定位(借鉴csdn上大神)
写博客是为了记录下来,毕竟好多东西记不住,看过就忘了,收藏又太多,还不如搬运到自己博客下面,随时可翻~~~ 近期再学目标识别与定位,看着原理都很简单,但是真自己做,又觉得困难重重. csdn上一个大神 ...
- 高并发的socket的高性能设计【转】
转自:https://blog.csdn.net/quincyfang/article/details/44654351 高性能数据传输系统的框架设计 1 引言 随着互联网和物联网的高速发展,使用网络 ...
- hibernate框架学习第二天:核心API、工具类、事务、查询、方言、主键生成策略等
核心API Configuration 描述的是一个封装所有配置信息的对象 1.加载hibernate.properties(非主流,早期) Configuration conf = new Conf ...
- Golang -- range小坑铭记
废话少叙,先上一段代码,猜猜预期的效果. package main import ( "fmt" ) type student struct { Name string Age i ...
- Linux 文档与目录结构
Linux之文档与目录结构 Linux文件系统结构 Linux目录结构的组织形式和Windows有很大的不同.首先Linux没有“盘(C盘.D盘.E盘)”的概念.已经建立文件系统的硬盘分区被挂载到 ...