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) ...
随机推荐
- php ecshop 二级域名切换跳转时session不同步,解决session无法共享同步导致无法登陆或者无法退出的问题
echshop基础上做了单点登录的 一级域名与二级域名 退出时 清空session 都是一级域名的session 因为二级域名的session是设置在二级域名上的 echshop基础上没有做单点登录的 ...
- python3 练习题100例 (三)
题目三:一个整数,它加上100后是一个完全平方数,再加上168又是一个完全平方数,请问该数是多少? #!/usr/bin/env python3 # -*- coding: utf-8 -*- &qu ...
- ruby做接口测试
一. 工具选择 IDE:rubymine:http接口请求:Unirest,ruby单元测试框架:rspec 二.工程创建 新建工程,在工程目录下,执行:rspec --init:初始化rspec工程 ...
- pip快速git项目安装
pip install git+https://github.com/xx/xx.git
- Go复习
# 代码包 #命名基础包 package “base” #导入基础包 import( "base1" ba "base2" 只导入当不使用情况下需要添加别名 . ...
- Codeforces431C_K-Tree_KEY
题目传送门 题目大意:给定一棵K叉树,一个节点下的K个节点的分数为i,求包含大于等于D的边的总分数为N的方案总数,mod 1e9+7. 这是一道很好的树形DP题,首先看N和K两个条件,可以轻易的得到方 ...
- Python-特殊变量
from test import test ''' __mame__ __file__ __cache__ __package__ ''' # import os # 获取这个当前文件的绝对路径 # ...
- libevent学习三(Getting an event_base)
1.一个event_base持有了一系列的事件,并监控和决定哪些事件需要激活, 2.每一个event_base背后都有一个支持其工作的方法(诸如select,poll,epoll,kquene...) ...
- 你的APK安全吗?来WeTest免费测!
腾讯安全联合实验室就曾在<2018上半年互联网黑产研究报告>指出,移动端黑产规模宏大,恶意推广日均影响用户超过千万. 尤其在网络强相关的APP流行年代,当APP应用客户端上传与获取信息,大 ...
- Qt官方开发环境生成的exe发布方式
本来想自己写一个打包程序的文章了,但是我发现了宝贝,在这里,大神写的比我牛逼的多了,这里做一下搬运工 一是为了方便大家 二是为了以后方便自己找 原文链接:http://tieba.baidu.com/ ...