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

Ac code :

  1. #include<stdio.h>
  2. #include<stdlib.h>
  3. int cmp(const void *a,const void *b)
  4. {
  5. return *(int *)b-*(int *)a;
  6. }
  7. int main()
  8. {
  9. int L, N, i;
  10. int a[601], sum, len;
  11. while(scanf("%d",&L)!=EOF)
  12. {
  13. scanf("%d",&N);
  14. for(i = 0; i < N; i++)
  15. scanf("%d",&a[i]);
  16. qsort(a, N, sizeof(a[0]), cmp);
  17. sum = len = 0;
  18. for(i = 0; i < N; i++)
  19. {
  20. if(len < L)
  21. {
  22. len += a[i];
  23. sum++;
  24. }
  25. else
  26. break;
  27. }
  28. if(len < L)
  29. printf("impossible\n");
  30. else
  31. printf("%d\n",sum);
  32. }
  33. return 0;
  34. }

  

--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. [资料]Keychain 获取设备唯一

    BAIDU http://blog.csdn.net/wonengxing/article/details/42142595 http://www.cnblogs.com/max5945/archiv ...

  2. C语言 链表的创建--打印--逆置--新增--删除--排序--释放

    #define _CRT_SECURE_NO_WARNINGS #include<stdio.h> #include<stdlib.h> #include<string. ...

  3. C语言 百炼成钢18

    //题目52:用递归打印以下图形 //* //*.*. //*..*..*.. //*...*...*...*... //*....*....*....*....*.... #include<s ...

  4. pre标签避免一行过长打破格局

    pre{ white-space:pre-wrap; word-wrap:break-word; word-break:break-all }

  5. AWS S3使用小结

    使用场景一:储存网站的图片,并能被任何人访问 1. 创建一个bucket,名字与需要绑定的域名一致. 例如,根域名是mysite.com,希望把所有图片放在pic.mysite.com下面,访问的时候 ...

  6. Linux 基础入门 第一周9.14~9.20

    第一节 Linux系统简介 Linux——操作系统 1.使多个用户从不同的终端同时操作主机(分时操作系统): 2.MINIX是一个功能有限的类似于UNIX的操作系统(UNIX 实现了 TCP/IP 协 ...

  7. Backbone小记录

    前言 这两天看了下Backbone.js的知识,大概了解了这个框架的一些知识. 写篇博客总结一下. Backbone.js是一个web端javascript的轻量级MVC框架.为什么说是轻量级呢?因为 ...

  8. IOS动态判断UITextField是否输入为手机号

    现在使用的app大部分都用到手机号注册,很多app注册的时候会判断手机号,可以根据当前输入文本来判断“获取验证码”的按钮是否可用 判断输入文本是通过UITextField的代理的 -(BOOL)tex ...

  9. 如何引用XML文件生成C#类

    目录 XSD File Generate Class File Simply. 1 Why use XSD file to create C# classes?... 2 How to convert ...

  10. 20步打造最安全的NGINX WEB服务器

    Nginx 是一个轻量级的,高性能的Web服务器以及反向代理和邮箱(IMAP/POP3)代理服务器.它运行在UNIX,GNU /linux,BSD 各种版本,Mac OS X,Solaris和Wind ...