hdu2124 Repair the Wall
来源:互联网 发布:知柏地 编辑:程序博客网 时间:2024/05/08 02:20
没多大意思的水题,题意是说修补屋子的1*n矩形漏洞,给定一些木块用最少的木块修补好裂缝,可使用锯子裁掉多余部分,应该算是简单的贪心算法,从大到小排序后累加,大于就可以跳出循环。。。。
附代码如下:
# include <iostream>
using namespace std;
__int64 a[650];
int cmp(int a, int b)
{
return a>b;
}
int main()
{
__int64 Lack, n;
while (scanf("%I64d %I64d", &Lack, &n) != EOF){
for (int i = 0; i < n; i ++){
scanf("%I64d", &a[i]);
}
sort(a, a+n, cmp);
__int64 sum = 0;
int check = 0;
int counter = 0;
for (int i = 0; i < n; i ++){
if (sum >= Lack){
check = 1;
break;
}
else {
sum += a[i];
counter ++;
}
}
if (sum >= Lack)check = 1;
if (check)printf("%d/n", counter);
else printf("impossible/n");
}
return 0;
}
- hdu2124 Repair the Wall
- hdu2124 Repair the Wall (贪心)
- HDU2124 Repair the Wall 【贪心】
- HDU2124 Repair the Wall(贪心)
- hdu2124--Repair the Wall(贪心水题)
- HDU2124——Repair the Wall(贪心水题)
- Repair the Wall+贪心
- Repair the Wall
- 2124:Repair the Wall
- Repair the Wall
- Repair the Wall
- Repair the Wall
- Repair the Wall
- Repair the wall
- hdu1214 Repair the Wall
- Repair the Wall
- Repair the Wall
- hdu 2124 Repair the Wall
- sql分页
- GetLastError
- 芯片测试问题
- linux php apache nginx mysql yum http lnmp centos ubuntu fedora eaccelerator phpMyAdmin php-fpm 编译 配置
- 通用分页类 (asp.net C#)
- hdu2124 Repair the Wall
- jQuery 学习笔记网
- 数字分页导航条 (asp.net C#)
- ExtJs中的TextField显示另外的值
- 同一数据库中两个表中复制数据
- C#的6种常用集合类
- WM_MOUSEWHEEL在多屏下的BUG
- 关于API和OAuth授权验证
- java 1.5 新特性-注解