简单贪心) 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号了,因为这一天是发工资的日 ...
随机推荐
- thinkphp视图中插入php代码
性别: <?php if($item['sex'] == 1):?> 男 <?php else:?> 女 <?php endif;?> 错误:<?php ec ...
- C-Lodop对大小写敏感 不要使用大小混写
C-Lodop是对大小写敏感的,而以前的Lodop控件,对于大小混写有可能可以用,而目前由于高版本的火狐谷歌不再支持np插件,为了兼容所有浏览器,就要使用c-lodop,或像Lodop官网的样例一样, ...
- ubuntu16.04下 搭建 lnmp 环境
apt-get install nginx apt-get php7.-mysql apt-get install mysql 编辑nginx配置文件 vim /etc/nginx/sites-ena ...
- JavaScript简单简介
JavaScript,男,web页面的一种脚本编程语言,1955年诞生,妻子为HTML,魔法能力是将静态页面(经过与用户交互与相应)转变为动态页面. 刚进入浏览器市场(魔界)的时候,也就是js1.0岁 ...
- java zip API实现压缩和解压缩zip包
package zip; import java.io.BufferedInputStream; import java.io.BufferedOutputStream; import java.io ...
- BZOJ4873[Shoi2017]寿司餐厅——最大权闭合子图
题目描述 Kiana最近喜欢到一家非常美味的寿司餐厅用餐.每天晚上,这家餐厅都会按顺序提供n种寿司,第i种寿司有一个 代号ai和美味度di,i,不同种类的寿司有可能使用相同的代号.每种寿司的份数都是无 ...
- 读取CSV到DataTable
using System; using System.Collections.Generic; using System.Data; using System.Data.OleDb; using Sy ...
- Scratch 简单的小游戏 --- 碰碰球
Scratch 简单的小游戏 --- 碰碰球 ================================ 积木脚本块的简要分类: 1. 角色 2. 背景 3. 角色和背景组成的场景 4. 挡板角 ...
- 【QML与C++混合编程】用QVariantList传递数组类型成员
2017.5.8 更新:Record类要用指针,QObject 不能有拷贝函数. 我有一个C++中自定义的ReaderModel,继承自QAbstractListModel类,传递给了QML. 它的m ...
- 【hjmmm网络流24题补全计划】
本文食用方式 按ABC--分层叙述思路 可以看完一步有思路后自行思考 飞行员配对问题 题目链接 这可能是24题里最水的一道吧... 很显然分成两个集合 左外籍飞行员 右皇家飞行员 跑二分图最大匹配 输 ...