杭电 2124 Repair the Wall(贪心)
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
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 i th integer Ai(0<Ai<1000000000 ) means that the i th block has the size of 1×Ai (in inch).
Output
If Kitty could not repair the wall, just print "impossible" instead.
Sample Input
Sample Output
#include<cstdio>
#include<algorithm>
using namespace std;
int a[];
bool cmp(int a,int b)
{
return a>b;
}
int main()
{
int m,n,i,j;
int sum;
while(scanf("%d %d",&m,&n)!=EOF)
{
sum=;
j=;
for(i=; i < n; i++)
{
scanf("%d",&a[i]);
}
sort(a,a+n,cmp);
for(i=;i<n;i++)
{
sum+=;
m-=a[i];
if(m <= )
{
j=-;
printf("%d\n",sum);
break;
}
}
if(j == ) printf("impossible\n");
}
}
杭电 2124 Repair the Wall(贪心)的更多相关文章
- --hdu 2124 Repair the Wall(贪心)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2124 Ac code : #include<stdio.h> #include<st ...
- HDU 2124 Repair the Wall
http://acm.hdu.edu.cn/showproblem.php?pid=2124 Problem Description Long time ago , Kitty lived in a ...
- 杭电 2111 Saving HDU (贪心)
Description 话说上回讲到海东集团面临内外交困,公司的元老也只剩下XHD夫妇二人了.显然,作为多年拼搏的商人,XHD不会坐以待毙的. 一天,当他正在苦思冥想解困良策的时候,突然想到了自己 ...
- 杭电 1009 FatMouse' Trade (贪心)
Problem Description FatMouse prepared M pounds of cat food, ready to trade with the cats guarding th ...
- 简单贪心) Repair the Wall hdu2124
Repair the Wall http://acm.hdu.edu.cn/showproblem.php?pid=2124 Time Limit: 5000/1000 MS (Java/Others ...
- 杭电OJ1789、南阳OJ236(贪心法)解题报告
杭电OJ1789http://acm.hdu.edu.cn/showproblem.php?pid=1789 南阳OJ236http://59.69.128.203/JudgeOnline/probl ...
- Repair the Wall (贪心)
Long time ago , Kitty lived in a small village. The air was fresh and the scenery was very beautiful ...
- HDU2124 Repair the Wall(贪心)
Problem Description Long time ago , Kitty lived in a small village. The air was fresh and the scener ...
- 杭电ACM分类
杭电ACM分类: 1001 整数求和 水题1002 C语言实验题——两个数比较 水题1003 1.2.3.4.5... 简单题1004 渊子赛马 排序+贪心的方法归并1005 Hero In Maze ...
随机推荐
- 状压dp之二之三 炮兵阵地/玉米田 By cellur925
一.简单的状压dp 玉米田 题目描述 Farmer John has purchased a lush new rectangular pasture composed of M by N (1 ≤ ...
- C语言之图像旋转
最近用到了图像向左或者向右旋转90°的情况,纠结了好一会儿,写下来供大家参考. 1 向左旋转90° //unsigned char *pImgData: 输入图像指针 //int WidthIn, i ...
- [poj2096] Collecting Bugs【概率dp 数学期望】
传送门:http://poj.org/problem?id=2096 题面很长,大意就是说,有n种bug,s种系统,每一个bug只能属于n中bug中的一种,也只能属于s种系统中的一种.一天能找一个bu ...
- 51nod 1024 矩阵中不重复的元素
1024 矩阵中不重复的元素 题目来源: Project Euler 基准时间限制:1 秒 空间限制:131072 KB 分值: 10 难度:2级算法题 收藏 关注 一个m*n的矩阵. 该矩阵的 ...
- Thinkpad x230设置启动顺序
设置可以从CD或者USB启动1.F1进入BIOS,Security → Secure Boot ,设置为:Disabled2.Startup → UEFI/Legacy Boot ,设置为:Both( ...
- Oracle报错:“ORA-18008: 无法找到 OUTLN 方案 ”的解决方案
Oracle报错:“ORA-18008: 无法找到 OUTLN 方案 ”的解决方案 2.修改replication_dependency_tracking参数 SQL> alter syst ...
- windows系统下如何正确安装Cygwin(图文详解)
我的操作系统信息是 1.在官网https://cygwin.com/install.html下载win64位安装包 选择包的下载存放目录,点击“下一步” 为了使我们安装的Cygwin能够编译程序, ...
- URAL1389. Roadworks(dp)
1389 算个简单的树形DP吧 不知道是不是数据太水 竟然一A了 就是对于当前节点有没有被选中就行选最优 有没有被选中的意思是有没有与它相连的边被选中 #include <iostream> ...
- 一个完整的http请求分析
Request URL:http://localhost:8080/test.jhtmlRequest Method:POSTStatus Code:200 OKRemote Address:[::1 ...
- Android图片压缩,不失真,上线项目
当然了,图片压缩是利用了libjpeg库的基础上,牛逼的同学可以自行生成so.jar.在此给出一个链接: http://www.cnblogs.com/hrlnw/p/4403334.html 在生成 ...