简单贪心) 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号了,因为这一天是发工资的日 ...
随机推荐
- 转载 -- jquery easyui datagrid 动态表头 + 嵌套对象属性展示
代码功能: 1.datagrid 的表头由后台生成,可以配置在数据库 2.datagrid 的列绑定数据 支撑嵌套对象 $(function() { var columns = new Array() ...
- ExportHandler.ashx
using KYZWeb.Common;using Liger.Data;//using Microsoft.Office.Interop.Excel;using System;using Syste ...
- 一般服务器端口号的反斜杠表示访问webapp下的资源
- 三星Galaxy S10可望率先应用于1TB的手机内存
导读 三星电子(Samsung Electronics)1月30日宣布,已经开始量产业界首款容量高达1TB的嵌入式通用闪存存储器(embedded Universal Flash Storage,eU ...
- centos6 nginx 安装【转】
原文 https://www.cnblogs.com/yaoximing/p/6068622.html 1.下载nginx 方法一 wget http://nginx.org/download/ngi ...
- 使用Promise解决多层异步调用的简单学习【转】
前言 本文章转载文章: https://www.jianshu.com/p/29da9aef4c1c 第一次接触到Promise这个东西,是2012年微软发布Windows8操作系统后抱着作死好奇的心 ...
- 基准对象object中的基础类型----字典 (六)
object有如下子类: CLASSES object basestring str unicode buffer bytearray classmethod complex dict enumera ...
- day2 网络基础
网路基础 网络OSI模型七层: 物理层: 定义特性:机械,电器,功能,过程: 定义接口标准:双绞线,光纤,同轴电缆: 相关协议:无: 数据链路层: 定义帧的开始结束,封装成帧,差错校验,透明传输(防止 ...
- navicat激活
参考:https://www.jianshu.com/p/5f693b4c9468 一开始想激活12.1.8,但是激活按钮一直点不了,换了个12.0激活成功
- 支持markwon写ppt的工具marp-调研
1.需求 使用markdown写ppt 支持大部分markdown语法,含高亮.公式及表格等 支持转为html,在浏览器中展示 2.调研 符合条件的工具:marp 用法参考 Marp之简单编写PPT格 ...