问题 D: 2132 Repair the Wall

题目描述

Long time ago , Kitty lived in a small village. The air was fresh and the scenery was very beautiful. The only thing that troubled her is the typhoon.
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 ?

输入
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,1000000000] and N, 0<=N<600 which mentioned above.
In the second line, there are N positive integers. The ith integer Ai(0~000000000 ) 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 <iostream>
#include <algorithm>
using namespace std;bool cmp(int a, int b) {return a > b;
}
int main() {int L, N;while(cin>>L >> N) {int a[N] = {0};for (int i = 0; i < N; i++) {cin>> a[i];}sort(a, a+N, cmp);for (int i = 0; i < N; i++) {if (a[i] > L) {cout<<i+1<<endl;L -= a[i];break;}else {L -= a[i];}}if (L > 0) cout<<"impossible"<<endl;}return 0;
}

[codeup 2132] Repair the Wall相关推荐

  1. XYNUOJ 1246: Repair the Wall 贪心水题 酒馆浪人的博客

    这道题完全就是大水题 1246: Repair the Wall 时间限制:  1 Sec   内存限制:  32 MB 提交:  26   解决:  13 [ 提交 ][ 状态 ][ 讨论版 ] 题 ...

  2. codeup墓地目录(算法笔记习题刷题笔记)

    在线codeup contest 地址:http://codeup.cn/contest.php Contest100000575 - <算法笔记>3.1小节--入门模拟->简单模拟 ...

  3. codeup墓地目录

    代码内容为原创C++ 在线codeup contest 地址:http://codeup.cn/contest.php Contest100000575 - <算法笔记>3.1小节--入门 ...

  4. 算法笔记CodeUp第一至第六章刷题记录

    文章目录 <算法笔记>2.2小节--C/C++快速入门->顺序结构 1.例题1-1-1 按要求输出信息(1) 2.例题1-1-2 按要求输出信息(2) 3.例题1-2-1 求两个整数 ...

  5. 高德地图API POI分类编码表(mysql版)

    高德地图API POI分类编码表(mysql版)   编码表更新时间:2017年8月10日   注意:本编码表为高德地图自定义编码格式,数据会根据行政区划变动不定期进行更新. sql文件下载地址: h ...

  6. 269道各路算法考试题集锦

    1 某编程大赛题(35道题,中等难度) 1.在实际的开发工作中,对于string的处理是最常见的编程任务,本题是要求程序对用户输入的string进行处理,具体要求如下: 1.每个单词的首字母变为大写. ...

  7. Java解惑 电子书

    --表达式谜题 Java 谜题 1--表达式谜题 谜题 1:奇数性 下面的方法意图确定它那唯一的参数是否是一个奇数.这个方法能够正确运转 吗? public static boolean isOdd( ...

  8. 【POJ1113】Wall(凸包)

    [题目] Description Once upon a time there was a greedy King who ordered his chief Architect to build a ...

  9. BZOJ 2132 圈地计划(最小割)【BZOJ 修复工程】

    整理的算法模板合集: ACM模板 点我看算法全家桶系列!!! 实际上是一个全新的精炼模板整合计划 题目链接 https://hydro.ac/d/bzoj/p/2132 是 hydro 的 BZOJ ...

  10. mysql之基础操作grant、show、repair、log_error等

    grant all on databasename.tablename to 'username'@'xxx.xxx.xxx.xxx' identified by 'complexpassword'; ...

最新文章

  1. LeetCode简单题之查找共用字符
  2. 我的理想计算机应用作文,我的理想当编程师作文400字
  3. CentOS 7 下 Zeal 安装
  4. 认识计算机ppt封面,认识计算机.ppt
  5. socket.io 中文手册 socket.io 中文文档
  6. 明天开始新的作息时间了
  7. 35 FI配置-财务会计-应收账款和应付账款-为客户定义备选统驭科目
  8. 华为HCIE7-中间系统到中间系统的路由泄露、防环、认证和优化机制
  9. leetcode 198 python
  10. python函数执行顺序_python下for循环接if判断的函数执行顺序
  11. C语言getchar函数
  12. Linux学习总结(34)——Linux系统目录结构详解
  13. JavaSE基础——方法参数类型及返回值类型问题、权限修饰符、内部类、匿名内部类
  14. 企业为什么需要IT服务台(二)
  15. 学大伟业:学习物理竞赛的学生如何快速掌握所需要的高数知识?
  16. Markov blanket 马尔科夫毯子
  17. mysql8.0源码分析——文件管理fil_system
  18. python数据分析经典书籍有哪些_数据分析有哪些好书值得推荐?
  19. c语言编程图形篮球,c语言程序设计 用高级语言实现篮球联赛个人技术数据处理系统...
  20. 高丽参的作用与功效及忌讳

热门文章

  1. 线程的简单理解,适用于初接触的小白,另类例子讲解,通俗易懂
  2. android 图片自动移动位置信息,android – 使用翻译动画将ImageView从当前位置移动到固定位置...
  3. android gesture,Android Gesture 手势创建以及使用示例
  4. 共享网络获取树莓派ip_树莓派网络设置
  5. linux夸分区软连接的作用,Linux 硬连接和软连接的原理 (in使用)
  6. 点击控件动态创建新页面
  7. 史上最完整的MySQL注入
  8. 开发者的实用 Vim 插件(二)
  9. 生成动态代理并加入系统功能的设计模板
  10. TableViewCell的折展(Masonry)