简单贪心) Repair the Wall hdu2124
Repair the Wall
http://acm.hdu.edu.cn/showproblem.php?pid=2124
Time Limit: 5000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 6833 Accepted Submission(s): 3174
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<iostream>
#include<algorithm>
using namespace std;
typedef long long ll;
ll a[];
bool cmp(ll a,ll b){ //用这个来进行降序排列吧,用greater<int>()可能会没过。
return a>b;
}
int main(){
ll len,m;
while(~scanf("%lld%lld",&len,&m)){
for(int i = ;i < m;i++){
scanf("%lld",&a[i]);
}
sort(a,a+m,cmp);
ll sum = ;
ll cnt = ;
int i;
for (i = ;i<m;i++){
sum += a[i];
cnt++;
if(sum>=len){
break;
}
}
if(i==m){
printf("impossible\n");
}
else{
printf("%d\n",cnt);
}
}
return ;
}
简单贪心) Repair the Wall hdu2124的更多相关文章
- HDU2124 Repair the Wall(贪心)
Problem Description Long time ago , Kitty lived in a small village. The air was fresh and the scener ...
- 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 ...
- CF 628C --- Bear and String Distance --- 简单贪心
CF 628C 题目大意:给定一个长度为n(n < 10^5)的只含小写字母的字符串,以及一个数d,定义字符的dis--dis(ch1, ch2)为两个字符之差, 两个串的dis为各个位置上字符 ...
- Uva 11729 Commando War (简单贪心)
Uva 11729 Commando War (简单贪心) There is a war and it doesn't look very promising for your country. N ...
- Repair the Wall
问题 : Repair the Wall 时间限制: 1 Sec 内存限制: 128 MB 题目描述 Long time ago , Kitty lived in a small village. ...
- CDOJ 1502 string(简单贪心)
题目大意:原题链接 相邻两个字母如果不同,则可以结合为前一个字母,如ac可结合为a.现给定一个字符串,问结合后最短可以剩下多少个字符串 解体思路:简单贪心 一开始读题时,就联想到之前做过的一道题,从后 ...
- HDU 2124 Repair the Wall
http://acm.hdu.edu.cn/showproblem.php?pid=2124 Problem Description Long time ago , Kitty lived in a ...
- ACM_发工资(简单贪心)
发工资咯: Time Limit: 2000/1000ms (Java/Others) Problem Description: 作为广财大的老师,最盼望的日子就是每月的8号了,因为这一天是发工资的日 ...
随机推荐
- Lodop打印html数字间隔不一致
在font-size属性控制数字大小的时候,可能会出现数字间隔有问题,间隔不一致,可尝试用其他字体大小试试,一般字体越小,越可能出现问题. 如图,前两个打印项都是form1,样式一个是style1,一 ...
- html class选择器与id选择器
class选择器: <p class="p1"> .p1{ color:red; ..... } id选择器: <p id="p2"> ...
- sql中的begin catch 。。。end catch 的用法
begin catch ...end catch 是用来处理异常的 begintry--SQLendtry begincatch--sql (处理出错动作)endcatch 我们将可能会出错的sql ...
- CML\LVDS
LVDS和CML电平应用区别 https://wenku.baidu.com/view/6bb0066f011ca300a6c3908c.html
- matlab——sparse函数和full函数
转载:http://www.cnblogs.com/lihuidashen/p/3435883.html matlab——sparse函数和full函数(稀疏矩阵和非稀疏矩阵转换) 函数功能:生成 ...
- openblas下载安装编译
编译好的库: https://github.com/JuliaLinearAlgebra/OpenBLASBuilder/releases 源码编译 下载:https://github.com/xia ...
- BZOJ2040[2009国家集训队]拯救Protoss的故乡——模拟费用流+线段树+树链剖分
题目描述 在星历2012年,星灵英雄Zeratul预测到他所在的Aiur行星在M天后会发生持续性暴雨灾害,尤其是他们的首都.而Zeratul作为星灵族的英雄,当然是要尽自己最大的努力帮助星灵族渡过这场 ...
- POJ 2750 鸡兔同笼
参考自:https://www.cnblogs.com/ECJTUACM-873284962/p/6414781.html POJ 2750鸡兔同笼 总时间限制:1000ms 内存限制:65536kB ...
- codechef EBAIT Election Bait【欧几里得算法】
题目分析: 欧几里得算法来处理一类分数问题,分数问题的形式如下 $\frac{a}{b} < \frac{p}{q} < \frac{c}{d}$ 当a=0时,答案等于$\frac{1}{ ...
- [洛谷P1273] 有线电视网
类型:树形背包 传送门:>Here< 题意:给出一棵树,根节点在转播足球赛,每个叶子节点是一个观众在收看.每个叶子结点到根节点的路径权值之和是该点转播的费用,每个叶子节点的观众都会付val ...