Problem Description

Long time ago , Kitty lived in a small village. The air was fresh and the scenery was very beautiful. The only thing that troubled her is the typhoon.

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 ?

Input

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).

Output

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.

Sample Input

5 3
3 2 1
5 2
2 1

Sample Output

2
impossible

Author

linle

Source

HDU 2007-10 Programming Contest

#include<stdio.h>
#include<string.h>
#include<math.h>
#include<stdlib.h>
#include<algorithm>
using namespace std;
const int maxn=+;
bool cmp(int a,int b)
{
return a>b;
}
int main()
{
int len,n,i,res;
int a[maxn];
while(scanf("%d%d",&len,&n)!=EOF)
{
for(i=;i<n;i++)scanf("%d",&a[i]);
sort(a,a+n,cmp);
res=;
for(i=;i<n;i++)
{
if(a[i]>=len)
{
res++;
len-=a[i];
break;
}
else
{
len-=a[i];
res++;
}
}
if(len>)printf("impossible\n");
else printf("%d\n",res);
}
return ;
}

HDU2124 Repair the Wall(贪心)的更多相关文章

  1. --hdu 2124 Repair the Wall(贪心)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2124 Ac code : #include<stdio.h> #include<st ...

  2. 简单贪心) Repair the Wall hdu2124

    Repair the Wall http://acm.hdu.edu.cn/showproblem.php?pid=2124 Time Limit: 5000/1000 MS (Java/Others ...

  3. Repair the Wall (贪心)

    Long time ago , Kitty lived in a small village. The air was fresh and the scenery was very beautiful ...

  4. 杭电 2124 Repair the Wall(贪心)

    Description Long time ago , Kitty lived in a small village. The air was fresh and the scenery was ve ...

  5. Repair the Wall

    问题 : Repair the Wall 时间限制: 1 Sec  内存限制: 128 MB 题目描述 Long time ago , Kitty lived in a small village. ...

  6. HDU 2124 Repair the Wall

    http://acm.hdu.edu.cn/showproblem.php?pid=2124 Problem Description Long time ago , Kitty lived in a ...

  7. 1724: [Usaco2006 Nov]Fence Repair 切割木板( 贪心 )

    倒过来看 , 每次总是选择最短的两块木板合并 , 用heap维护 ------------------------------------------------------------------- ...

  8. Fence Repair POJ - 3253 (贪心)

    Farmer John wants to repair a small length of the fence around the pasture. He measures the fence an ...

  9. BZOJ 1724: [Usaco2006 Nov]Fence Repair 切割木板 贪心 + 堆 + 反向思考

    Description Farmer John想修理牧场栅栏的某些小段.为此,他需要N(1<=N<=20,000)块特定长度的木板,第i块木板的长度为Li(1<=Li<=50, ...

随机推荐

  1. USACO 4.2 Drainage Ditches(网络流模板题)

    Drainage DitchesHal Burch Every time it rains on Farmer John's fields, a pond forms over Bessie's fa ...

  2. Java动态代理简单应用

    概念 代理模式是基本的设计模式之一,它是开发者为了提供额外的或不同的操作,而插入的用来代替“实际”对象的对象.这些操作通常涉及与“实际”对象的通信,因此代理通常充当着中间人的角色. Java动态代理比 ...

  3. response.addCookie(cookie)添加cookie失败.

    两个if循环能进来,创建的两个cookie也能通过控制台输出.  但是却添加失败. 原因是:request.getRequestDispatcher("/MainFrame").f ...

  4. 图片,音频资源预加载和文档dom加载

    在项目中遇到一个问题,ajax请求音频资源,然后动态的插入到文档中,其中.原生的音频外观实在太丑了,而且每个浏览器的样式都不一样,采取了一个audio插件. 就遇到一个问题,请求后的直接调用插件的话, ...

  5. 必须掌握的Linux命令

    章节简述: 本章节讲述系统内核.Bash解释器的关系与作用,教给读者如何正确的执行Linux命令以及常见排错方法. 经验丰富的运维人员可以恰当的组合命令与参数,使Linux字符命令更加的灵活且相对减少 ...

  6. 【5】图解HTTP 笔记

    坚持.聪明.不畏困难,我将取得最后的胜利. 第一章 了解 Web 以网络基础 1. HTTP ( HyperText Transfer Protocol ): 超文本传输协议. 2. 通讯方式: 3. ...

  7. PEiD 0.95 全插件中文绿色版

    软件名称: PEiD 0.95 软件语言: 简体中文 授权方式: 免费软件 运行环境: Win8 / Win7 / Vista / WinXP 软件大小: 4.4MB 图片预览: 软件简介: PEiD ...

  8. CSS3 Filter滤镜效果

    关注到它是在一次分享会当中,很神奇,只需写一行代码就可以变身很美的视觉效果,这就是CSS3滤镜. 语法 filter:fuction(param); 如今浏览器支持情况相比以前乐观很多,点击查看兼容 ...

  9. [阿当视频]WEB组件学习笔记

    — 视频看完了,自定义事件还不懂,等完全懂了再更新并完成整篇案例 1. JS分层和组件的种类浏览器底层包括HTML CSS JS(DOM/BOM/Style/Canvas 2D/WebGl/SVG) ...

  10. 4、Xcode8中的钥匙串保存数据取出时候为空的问题

    Xcode7以及之前的版本直接使用Keychain存储数据即可,但是从Xcode8开始,再用之前的方法会发现,读取不到存进去的数据了,或者说,存储不进去了,原因是苹果加强了隐私保护,这个东西需要打开开 ...