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 ...
随机推荐
- MySQL - COUNT关键字
基础数据信息 SELECT COUNT(*) AS '用户名的个数' FROM t_user SELECT COUNT(DISTINCT username) AS '用户名不重复的个数' FROM t ...
- python - 中文编码/ASCII
Python 中文编码 为了处理汉字,程序员设计了用于简体中文的GB2312和用于繁体中文的big5. GB2312(1980年)一共收录了7445个字符,包括6763个汉子和682个其他符号. ...
- java多线程面试题小结
http://www.importnew.com/12773.html http://www.cnblogs.com/fingerboy/p/5352880.html https://blog.csd ...
- 【转载】AutoML--超参数调优之Bayesian Optimization
原文:Auto Machine Learning笔记 - Bayesian Optimization 优化器是机器学习中很重要的一个环节.当确定损失函数时,你需要一个优化器使损失函数的参数能够快速有效 ...
- google 开源项目阅读计划
1. glog 2. gflags 3. carto 4. ...
- a.py
#!/usr/bin/python # -*- coding: UTF-8 -*- import os import sys import re import shutil import glob d ...
- Python os.removedirs() 和shutil.rmtree() 用于删除文件夹
概述 os.removedirs() 方法用于递归删除目录.像rmdir(), 如果子文件夹成功删除, removedirs()才尝试它们的父文件夹,直到抛出一个error(它基本上被忽略,因为它一般 ...
- linux TLB表
TLB - translation lookaside buffer 快表,直译为旁路快表缓冲,也可以理解为页表缓冲,地址变换高速缓存. 由于页表存放在主存中,因此程序每次访存至少需要两次:一次访存获 ...
- WebStorm 关联 TFS(转)
1.下载插件 TFS integration 2.链接TFS 服务器 3.创建工作区 4. 5.选择一个 工作环境 6.最重要的有点是在VCS里面要选择一个默认的提交方式!!!
- 020_nginx禁止ip默认参数是$remote_addr无法禁止真实ip的问题
由于网站使用了cdn所以$remote_addr获取的ip是cdn的ip,我现在先禁止某些ip访问发现无法禁止cdn传递过来的客户端的ip也就是$http_x_forwarded_for这个参数.比如 ...