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. 伪 alter 弹窗 +弹窗统一

    你应该有遇到这种情况:alert() 在手机上面显示的时候 反正是不好看  有的时候就只看到一个白色的框  看不到提示信息  反正很反人类  这时候我觉得 马上会有产品跟你说 这个要改掉. 然后我就遇 ...

  2. centos6.4、6.5、7.0环境下载及安装

    centos6.4.6.5.7.0下载地址: http://www.cnblogs.com/zhwl/p/3657958.html或 http://www.linuxdown.net/CentOS/2 ...

  3. ipad 横屏 竖屏 CSS

    /* iPads (landscape) ----------- */ @media only screen and (min-device-width : 768px) and (max-devic ...

  4. sublime & atom 插件

    1. autofilename(sublime) autocomplete-paths (atom): 自动路径 2. autoprefixer: 自动添加前缀  : https://github.c ...

  5. yarn计算一个节点容量及其配置项

    mapred-site.xml mapreduce.map.memory.mb 1536 每个Map Container的大小 mapreduce.reduce.memory.mb 2560 每个Re ...

  6. DateTime & UTC 相互转化

    public long ToUnixTime(DateTime date) { var epoch = new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.U ...

  7. DOM小解

    现在来说说DOM 文档对象模型DOM(Document Object Model)定义访问和处理html文档的标准方法.DOM将html文档呈现为带有元素   ,属性和文本的树结构(节点树) 先来看看 ...

  8. centos php nginx 添加到service

    1. nginx A. # vi /etc/init.d/nginx B. #!/bin/sh # Comments to support chkconfig on RedHat Linux # ch ...

  9. HTML中判断手机是否安装某APP,跳转或下载该应用

    有些时候在做前端输出的时候,需要和app的做些对接工作.就是在手机浏览器中下载某app时,能判断该用户是否安装了该应用.如果安装了该应用,就直接打开该应用:如果没有安装该应用,就下载该应用.那么下面就 ...

  10. 使用Image.GetThumbnailImage 方法返回缩略图

    如果 Image 包含一个嵌入式缩略图像,则此方法会检索嵌入式缩略图,并将其缩放为所需大小. 如果 Image 不包含嵌入式缩略图像,此方法会通过缩放主图像创建一个缩略图像. 请求的缩略图像大小为 1 ...