HDU 2124 Repair the Wall
http://acm.hdu.edu.cn/showproblem.php?pid=2124
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 ?
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).
If Kitty could not repair the wall, just print "impossible" instead.
#include <bits/stdc++.h>
using namespace std; int L, n;
int len[610]; bool cmp(int x, int y) {
return x > y;
} int main() {
while(~scanf("%d%d", &L, &n)) {
int sum = 0, cnt = 0;
for(int i = 1; i <= n; i ++)
scanf("%d", &len[i]); sort(len + 1, len + 1 + n, cmp);
while(sum < L && cnt <= n) {
sum += len[cnt + 1];
cnt ++;
}
if(cnt <= n)
printf("%d\n", cnt);
else
printf("impossible\n");
}
return 0;
}
HDU 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 ...
- 杭电 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 hdu2124
Repair the Wall http://acm.hdu.edu.cn/showproblem.php?pid=2124 Time Limit: 5000/1000 MS (Java/Others ...
- HDU2124 Repair the Wall(贪心)
Problem Description Long time ago , Kitty lived in a small village. The air was fresh and the scener ...
- hdu 3669 Cross the Wall(斜率优化DP)
题目连接:hdu 3669 Cross the Wall 题意: 现在有一面无限大的墙,现在有n个人,每个人都能看成一个矩形,宽是w,高是h,现在这n个人要通过这面墙,现在只能让你挖k个洞,每个洞不能 ...
- Repair the Wall
问题 : Repair the Wall 时间限制: 1 Sec 内存限制: 128 MB 题目描述 Long time ago , Kitty lived in a small village. ...
- Repair the Wall (贪心)
Long time ago , Kitty lived in a small village. The air was fresh and the scenery was very beautiful ...
- hdu 1543 Paint the Wall
http://acm.hdu.edu.cn/showproblem.php?pid=1543 #include <cstdio> #include <cstring> #inc ...
- HDU 4391 Paint The Wall(分块+延迟标记)
Paint The Wall Time Limit: 20000/10000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) ...
随机推荐
- transform Vs Udf
在鞋厂的第一个任务,拆表.需要把订单表按照开始日期和结束日期拆分成多条记录,挺新鲜的~ transform方式,使用到了python. (1)把hive表的数据传入,通过python按照日期循环处理, ...
- 对Python语法简洁的贴切描述
很多人认为,Python与其他语言相比,具有语法简洁的特点.但这种简洁到底体现在哪些地方,很少有人能说清楚.今天看到一个对这一问题的描述,个人觉得很不错,原文如下: “Python语法主要用来精确表达 ...
- Ruby中类的进阶(继承,private, public, protect)
类中的public,protect,private public method class Point def test end end 这样定义的test方法就是一个public方法可以在类内外使用 ...
- [BZOJ4552][Tjoi2016&Heoi2016]排序(二分答案+线段树)
二分答案mid,将>=mid的设为1,<mid的设为0,这样排序就变成了区间修改的操作,维护一下区间和即可 然后询问第q个位置的值,为1说明>=mid,以上 时间复杂度O(nlog2 ...
- 前端chrome调试技巧
待更新:http://blog.csdn.net/xueer767/article/details/65936204?locationNum=8&fps=1
- 【转】Odoo装饰器: one装饰
one装饰器的作用是对每一条记录都执行对应的方法,相当于traditional-style中的function,无返回值! 应用举例: 定义的columns now = fields.Datetime ...
- elasticsearch增删改查操作
目录 1. 插入数据 2. 更改数据 3. 删除数据 4. 检索文档 1. 插入数据 关于下面的代码如何使用,可以借助于kibana的console,浏览器打开地址: http://xxx.xxx.x ...
- Myeclipse - 问题集 - specified vm install not found
In Eclipse, click the ant file -- Run As -- External Tools Configuration and click on the JRE tab. S ...
- redis 类型、方法
之前使用redis,现在对所有redis方法做一个总结: string类型 形式:key=>value; 说明:最简单的类型:一个key对应一个value,value保存的类型是二进制安全的,s ...
- 使用redux-actions优化actions管理
redux-actions的api很少,有三个createAction(s) handleASction(s) combineActions 主要用到createAction去统一管理actio ...