HDU2124 Repair the Wall(贪心)
Problem Description
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
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
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
Source
#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(贪心)的更多相关文章
- --hdu 2124 Repair the Wall(贪心)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2124 Ac code : #include<stdio.h> #include<st ...
- 简单贪心) 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 ...
- 杭电 2124 Repair the Wall(贪心)
Description Long time ago , Kitty lived in a small village. The air was fresh and the scenery was ve ...
- Repair the Wall
问题 : Repair the Wall 时间限制: 1 Sec 内存限制: 128 MB 题目描述 Long time ago , Kitty lived in a small village. ...
- HDU 2124 Repair the Wall
http://acm.hdu.edu.cn/showproblem.php?pid=2124 Problem Description Long time ago , Kitty lived in a ...
- 1724: [Usaco2006 Nov]Fence Repair 切割木板( 贪心 )
倒过来看 , 每次总是选择最短的两块木板合并 , 用heap维护 ------------------------------------------------------------------- ...
- Fence Repair POJ - 3253 (贪心)
Farmer John wants to repair a small length of the fence around the pasture. He measures the fence an ...
- BZOJ 1724: [Usaco2006 Nov]Fence Repair 切割木板 贪心 + 堆 + 反向思考
Description Farmer John想修理牧场栅栏的某些小段.为此,他需要N(1<=N<=20,000)块特定长度的木板,第i块木板的长度为Li(1<=Li<=50, ...
随机推荐
- ipc 入侵步骤
第一步:建立IPC隧道net use \\10.56.204.186\IPC$ "密码" /user:"用户" 第二步:映射对方c盘到本地z盘net u ...
- CodeForces 213B Numbers
$dp$,组合数. $dp[i][j]$表示只用数字$i$,$i+1$,$i+2$......,$9$,凑成长度为$j$的并且数字$i$到$9$符合要求的方案数.只要枚举数字$i$用几个就可以转移了. ...
- 通过file文件选择图片预览功能
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...
- Java中的修饰符
-----------------------------------------------01----------------------------------------------- 类,方 ...
- python新手 实践操作 作业
#有如下值集合 [11,22,33,44,55,66,77,88,99],将所有大于 66 的值保存至字典的第一个key中,将小于 66 的值保存至第二个key的值中.即: {'k1': 大于66的所 ...
- 使用pycharm+pyqt5 调取界面程序
一.使用QtDesigner制作界面 1)打开的界面设计工具QtDesigner,如图: 2)新建窗体,选择Main Window: 3)分别在窗口添加如下控件,Calendar.3个pushButt ...
- 2016-2017 CT S03E02: Codeforces Trainings Season 3 Episode 2
A HHPaint B Square Root C Interesting Places D Road to Home E Ant and apples F Square G Pair H The F ...
- Kafka单机版安装(CentOS 7环境下)
一.环境操作系统和软件版本介绍 1.环境操作系统为CentOS Linux release 7.2.1511 (Core) 可用cat /etc/redhat-release查询 2.软件版本 Kaf ...
- GOPS2017全球运维大会 • 深圳站 历届金牌讲师精选亮相
GOPS2017全球运维大会 • 深圳站将于2017年4月21日-22日在深圳举行,GOPS2017报名平台:活动家! 快捷报名通道:http://www.huodongjia.com/event-2 ...
- Gs_Class.Gs_DataFunction数据操作类库20160225
using System;using System.Data;using System.Configuration;using System.Web;using System.Web.Security ...