题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2124

Ac code :

#include<stdio.h>
#include<stdlib.h>
int cmp(const void *a,const void *b)
{
return *(int *)b-*(int *)a;
}
int main()
{
int L, N, i;
int a[601], sum, len;
while(scanf("%d",&L)!=EOF)
{
scanf("%d",&N);
for(i = 0; i < N; i++)
scanf("%d",&a[i]);
qsort(a, N, sizeof(a[0]), cmp);
sum = len = 0;
for(i = 0; i < N; i++)
{
if(len < L)
{
len += a[i];
sum++;
}
else
break;
}
if(len < L)
printf("impossible\n");
else
printf("%d\n",sum);
}
return 0;
}

  

--hdu 2124 Repair the Wall(贪心)的更多相关文章

  1. HDU 2124 Repair the Wall

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

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

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

  3. 简单贪心) Repair the Wall hdu2124

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

  4. HDU2124 Repair the Wall(贪心)

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

  5. Repair the Wall (贪心)

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

  6. hdu 3669 Cross the Wall(斜率优化DP)

    题目连接:hdu 3669 Cross the Wall 题意: 现在有一面无限大的墙,现在有n个人,每个人都能看成一个矩形,宽是w,高是h,现在这n个人要通过这面墙,现在只能让你挖k个洞,每个洞不能 ...

  7. Repair the Wall

    问题 : Repair the Wall 时间限制: 1 Sec  内存限制: 128 MB 题目描述 Long time ago , Kitty lived in a small village. ...

  8. hdu 4825 Xor Sum(trie+贪心)

    hdu 4825 Xor Sum(trie+贪心) 刚刚补了前天的CF的D题再做这题感觉轻松了许多.简直一个模子啊...跑树上异或x最大值.贪心地让某位的值与x对应位的值不同即可. #include ...

  9. HDU 5813 Elegant Construction (贪心)

    Elegant Construction 题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5813 Description Being an ACMer ...

随机推荐

  1. Web的形式发布静态文件

    Web的形式发布静态文件 虽然ASP.NET Core是一款"动态"的Web服务端框架,但是在很多情况下都需要处理针对静态文件的请求,最为常见的就是这对JavaScript脚本文件 ...

  2. linux命令细究

    ls -ldahipFtr    -t按照修改时间    -r翻转排序 /etc/profile  别名grep --color ls -pF ^$空行egrep -v "^#|^$&quo ...

  3. 跳台阶 一只青蛙一次可以跳上1级台阶,也可以跳上2级。求该青蛙跳上一个n级的台阶总共有多少种跳法。

    class Solution { public: int jumpFloor(int number) { ) ; ) ; )+jumpFloor(number-); } }; 如果先建立数组,然后利用 ...

  4. C#字符格式化占位符

    using System; using System.Diagnostics; using System.Text; using System.Collections; using System.Co ...

  5. Volly框架的使用基础版及使用中的一些坑 Ace 网络篇(三)

    直接把注释粘过来: * Volley使用讲解: * 要实现网络数据请求主要要记住下面三步骤: * 1.创建RequestQueue对象 * 2.创建XXRequest对象(XX代表String,JSO ...

  6. 海量数据处理利器之Hash——在线邮件地址过滤

    标题用了了海量数据(Massive datasets)而不用大数据(Big data).感觉大数据还是略微有点虚,来点实际的. 一.需求 现在我们需要设计一个在线过滤垃圾邮件地址的方案,我们的数据库里 ...

  7. 一种仿照Asp.net Mvc思维构建WebSocket服务器的方法

    问题场景 Asp.net Mvc提供了DependencyResolver.Routing.Filter. Modelbinder等webForm所没有新概念,提高Web服务编写的便利性,记得很久之前 ...

  8. Java并发编程-CAS

    CAS(Compare and swap)比较和替换是设计并发算法时用到的一种技术.简单来说,比较和替换是使用一个期望值和一个变量的当前值进行比较,如果当前变量的值与我们期望的值相等,就使用一个新值替 ...

  9. C#中判断一个数组中是否存在某个数组值 及相关

    声明:reference:http://www.cnblogs.com/icebutterfly/archive/2010/06/22/1762738.html:http://blog.csdn.ne ...

  10. 使用TinkPHP实现品字形布局

    一.后台管理模版 后台管理模版通常使用frameset/iframe来布局.例如: <!DOCTYPE html> <html> <head> <title& ...