问题 : Repair the Wall

时间限制: 1 Sec  内存限制: 128 MB

题目描述

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<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的更多相关文章

  1. HDU2124 Repair the Wall(贪心)

    Problem Description Long time ago , Kitty lived in a small village. The air was fresh and the scener ...

  2. 简单贪心) Repair the Wall hdu2124

    Repair the Wall http://acm.hdu.edu.cn/showproblem.php?pid=2124 Time Limit: 5000/1000 MS (Java/Others ...

  3. Repair the Wall (贪心)

    Long time ago , Kitty lived in a small village. The air was fresh and the scenery was very beautiful ...

  4. HDU 2124 Repair the Wall

    http://acm.hdu.edu.cn/showproblem.php?pid=2124 Problem Description Long time ago , Kitty lived in a ...

  5. 杭电 2124 Repair the Wall(贪心)

    Description Long time ago , Kitty lived in a small village. The air was fresh and the scenery was ve ...

  6. --hdu 2124 Repair the Wall(贪心)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2124 Ac code : #include<stdio.h> #include<st ...

  7. hdu_2124 Flying to the Mars & hdu_1800 Repair the Wall 贪心水题

    hdu_1800 简单排一下序,从大开始把比他小的都访问一遍,ans++: #include <iostream> #include <stdio.h> #include &l ...

  8. TJU Problem 1090 City hall

    注:对于每一横行的数据读取,一定小心不要用int型,而应该是char型或string型. 原题: 1090.   City hall Time Limit: 1.0 Seconds   Memory ...

  9. [poj1113][Wall] (水平序+graham算法 求凸包)

    Description Once upon a time there was a greedy King who ordered his chief Architect to build a wall ...

随机推荐

  1. Python Django CBV下的通用视图函数

    ListView TemplateView DetailView 之前的代码实例基本上都是基于FBV的模式来撰写的,好处么,当然就是简单粗暴..正如: def index(request): retu ...

  2. Webstorm通用设置

    常用快捷键 Ctrl+Alt+L : 格式化代码

  3. python小练习,密码等级问题

    . # 密码安全性检查代码 . # . # 低级密码要求: . # . 密码由单纯的数字或字母组成 . # . 密码长度小于等于8位 . # . # 中级密码要求: . # . 密码必须由数字.字母或 ...

  4. list补充,append()、extend()、insert()、remove()、del()、pop()、分片

    1.添加 append(object),是指在列表的末尾添加一个元素. >>> arr = [1,2,'a','你好',[11,22,33]] >>> arr [1 ...

  5. Python 模拟鼠键

    让python 自动操作桌面或应用窗口,点击,滑动鼠标,输入文字等 # coding=utf-8 from pymouse import PyMouse from pykeyboard import ...

  6. 【SVN】SVN初识

    SVN 介绍 SVN是Subversion的简称,是一个开放源代码的版本控制系统,相较于RCS.CVS,它采用了分支管理系统,它的设计目标就是取代CVS.互联网上很多版本控制服务已从CVS迁移到Sub ...

  7. 利用微信企业号的告警功能,联动检测ICMP的shell脚本

    作者:邓聪聪 由于设备IP众多,为了及时发现IP地址有不可达现象,利用微信的联动报警,及时发现问题,以下是脚本内容!!! ping.sh #!/bin/bash ###SCRIPT_NAME:icmp ...

  8. vc++基础班[24]---系统各种路径信息的获取

    vc++基础班[24]---系统各种路径信息的获取 ------------------------------------------ Begin ------------------------- ...

  9. Python在线聊天软件(Tkinter)

    1.python2.7下安装 apt-get install python-tk 主要功能是实现客户端与服务器端的双向通信,这个小东西用到的主要知识点: 1.Python Socket:2.Pytho ...

  10. jvm 监控工具

    背景 不懂jvm监控工具好意思说自己搞java的吗.其实搞了十多年的人我都见过不懂得,不懂不要紧,老实工作就行啊.这就是属于非技术的话题了,实在不知从何说起.还是赶紧学习下吧,可以去装了.我认真学习后 ...