Repair the Wall
问题 : Repair the Wall
时间限制: 1 Sec 内存限制: 128 MB
题目描述
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.
输入
The problem contains many test cases, please process to the end of file( EOF ).
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).
输出
For each test case , print an integer which represents the minimal number of blocks are needed.
If Kitty could not repair the wall, just print "impossible" instead.
样例输入
2 2 12 11 14 3 27 11 4 109 5 38 15 6 21 32 5 3 1 1 1
样例输出
1 1 5 impossible
解题思路
水题,直接从大到小往上补就可以了。
#include <stdio.h>
#include <algorithm>
using namespace std;
int main()
{
int l, n, i, s[666];
while (~scanf("%d%d", &l, &n))
{
for (int i = 0; i < n; i++)
scanf("%d", &s[i]);
sort(s, s + n);
for (i = n - 1; i >= 0 && l > 0; i--)
l -= s[i];
if (l > 0)
puts("impossible");
else printf("%d\n", n - i - 1);
}
return 0;
}Repair the Wall的更多相关文章
- 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 hdu2124
Repair the Wall http://acm.hdu.edu.cn/showproblem.php?pid=2124 Time Limit: 5000/1000 MS (Java/Others ...
- Repair the Wall (贪心)
Long time ago , Kitty lived in a small village. The air was fresh and the scenery was very beautiful ...
- HDU 2124 Repair the Wall
http://acm.hdu.edu.cn/showproblem.php?pid=2124 Problem Description Long time ago , Kitty lived in a ...
- 杭电 2124 Repair the Wall(贪心)
Description Long time ago , Kitty lived in a small village. The air was fresh and the scenery was ve ...
- --hdu 2124 Repair the Wall(贪心)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2124 Ac code : #include<stdio.h> #include<st ...
- hdu_2124 Flying to the Mars & hdu_1800 Repair the Wall 贪心水题
hdu_1800 简单排一下序,从大开始把比他小的都访问一遍,ans++: #include <iostream> #include <stdio.h> #include &l ...
- TJU Problem 1090 City hall
注:对于每一横行的数据读取,一定小心不要用int型,而应该是char型或string型. 原题: 1090. City hall Time Limit: 1.0 Seconds Memory ...
- [poj1113][Wall] (水平序+graham算法 求凸包)
Description Once upon a time there was a greedy King who ordered his chief Architect to build a wall ...
随机推荐
- Print Article(斜率DP入门+单调队列)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3507 题目大意:给你n个数,然后问你怎么分割当前的这n个数位那几组,使得每一组的权值加起来最大.每一组 ...
- 关于setInterval返回值问题
oBtn1.onclick = function(){ clearInterval(timer); timer = setInterval(cwidth,10); alert(timer); } oB ...
- 【Udacity并行计算课程笔记】- Lesson 4 Fundamental GPU Algorithms (Applications of Sort and Scan)
I. Scan应用--Compact 在介绍这节之前,首先给定一个情景方便理解,就是因为某种原因我们需要从扑克牌中选出方块的牌. 更formal一点的说法如下,输入是 \(s_0,s_1,...\), ...
- 使用CloneDB克隆数据库
本节包含以下主题: 关于使用CloneDB克隆数据库 使用CloneDB克隆数据库 使用CloneDB克隆数据库后 关于使用CloneDB克隆数据库 出于测试目的或其他目的克隆生产数据库通常是必要的. ...
- Latex 编辑数学公式——快速上手
参考链接: https://blog.csdn.net/fansongy/article/details/45368915 特殊符号: https://blog.csdn.net/caiandyong ...
- CF1096E The Top Scorer
题目地址:洛谷CF1096E 本场AC数最少 (最难) 的题目 题目大意:给出三个数p , s,r,表示有p人,每个人都有一个非负得分,所有人的得分和为s,Hasan的得分至少为r,求Hasan是第一 ...
- PCA算法浅析
最近频繁在论文中看到「PCA」的影子,所以今天决定好好把「PCA」的原理和算法过程弄清楚. 「PCA」是什么 PCA,又称主成分分析,英文全称「Principal Components Analysi ...
- 【转】python包导入细节
[转]python包导入细节 包导入格式 导入模块时除了使用模块名进行导入,还可以使用目录名进行导入.例如,在sys.path路径下,有一个dir1/dir2/mod.py模块,那么在任意位置处都可以 ...
- 初识python异步模块Trio
Trio翻译过来是三重奏的意思,它提供了更方便异步编程,是asyncio的更高级的封装. 它试图简化复杂的asyncio模块.使用起来比asyncio和Twisted要简单的同时,拥有其同样强大功能. ...
- ES6学习笔记七Generator、Decorators
Generator异步处理 { // genertaor基本定义,next()一步步执行 let tell=function* (){ yield 'a'; yield 'b'; return 'c' ...