Hdu 3177 Crixalis's Equipment
Crixalis's Equipment
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 2795 Accepted Submission(s): 1141

Someday Crixalis decides to move to another nice place and build a new house for himself (Actually it's just a new hole). As he collected a lot of equipment, he needs to dig a hole beside his new house to store them. This hole has a volume of V units, and Crixalis has N equipment, each of them needs Ai units of space. When dragging his equipment into the hole, Crixalis finds that he needs more space to ensure everything is placed well. Actually, the ith equipment needs Bi units of space during the moving. More precisely Crixalis can not move equipment into the hole unless there are Bi units of space left. After it moved in, the volume of the hole will decrease by Ai. Crixalis wonders if he can move all his equipment into the new hole and he turns to you for help.
0<T<= 10, 0<V<10000, 0<N<1000, 0 <Ai< V, Ai <= Bi < 1000.
贪心.
贪心策略:当前放的物品所需的空间 Bi 和 下一个需要放的物品所占用空间 Aj 之和是否大于 当前物品所占用空间 Ai 和下一个物品所需空间 Bi 之和.
也就是(Bi+Aj)>(Bj+Ai)的话 就先放物品i 否则 先放物品j
需要空间大的先放.
可以用一组案例来思考一下这个贪心策略:
20 3
10 20
3 4
7 7
___________
代码如下:
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
#define MAX 1001
struct node
{
int a;
int b;
};
struct node x[MAX];
int v,n;
bool cmp(struct node x,struct node y)
{
if(x.b==y.b) return x.a>y.a;
return (x.b-x.a)>(y.b-y.a);
}
void init()
{
memset(x,,sizeof(x));
}
void read()
{
int i;
scanf("%d %d",&v,&n);
for(i=;i<n;i++)
scanf("%d %d",&x[i].a,&x[i].b);
sort(x,x+n,cmp);
}
void cal()
{
int i;
int res=v;
for(i=;i<n;i++)
{
if(res<||res<x[i].b)
{
res-=x[i].b;
break;
}
res-=x[i].a;
}
if(res>=) printf("Yes\n");
else printf("No\n");
}
void solve()
{
init();
read();
cal();
} int main()
{
int t;
scanf("%d",&t);
while(t--)
{
solve();
}
return ;
}
Hdu 3177 Crixalis's Equipment的更多相关文章
- 【hdu 3177 Crixalis's Equipment】 题解
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3177 \(describe\): 有一个山洞,山洞的容积最大为\(v\).现在你有\(n\)个物品,这 ...
- HDU 3177 Crixalis's Equipment (贪心,差值)
题意:判断 n 件物品是否可以搬进洞里,每件物品有实际体积A和移动时的额外体积 B . 析:第一反应就是贪心,一想是不是按B从大到小,然后一想,不对,比如体积是20,第一个 是A=11, B=19.第 ...
- HDU ACM 3177 Crixalis's Equipment
Crixalis's Equipment Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Oth ...
- hdu 3177 Crixalis's Equipment
Crixalis's Equipment Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Oth ...
- HDU 3177 Crixalis's Equipment(贪婪)
主题链接:http://acm.hdu.edu.cn/showproblem.php? pid=3177 Problem Description Crixalis - Sand King used t ...
- 杭电 3177 Crixalis's Equipment
http://acm.hdu.edu.cn/showproblem.php? pid=3177 Crixalis's Equipment Time Limit: 2000/1000 MS (Java/ ...
- HDOJ 3177 Crixalis's Equipment
Crixalis's Equipment Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Oth ...
- hdu---3177 Crixalis's Equipment 根据 两个元素 之间的权衡进行排序
Crixalis's Equipment Problem Description Crixalis - Sand King used to be a giant scorpion(蝎子) in the ...
- HD-ACM算法专攻系列(23)——Crixalis's Equipment
题目描述: AC源码:此次考察贪心算法,解题思路:贪心的原则是使留下的空间最大,优先选择Bi与Ai差值最大的,至于为什么?这里用只有2个设备为例,(A1,B1)与(A2,B2),假设先搬运A1,搬运的 ...
随机推荐
- Lamda和Linq语法对比详细
本人转载:http://www.cnblogs.com/knowledgesea/p/3897665.html 闲言碎语 近期比较忙,但还是想写点什么,就分享一些基础的知识给大家看吧,希望能帮助一些l ...
- shell 脚本执行日志通用模块
目标 实现记录SHELL执行的開始时间,结束时间.执行状态,错误信息等,以函数封装日志记录的方式,脚本调用函数 源代码 通用函数脚本program_log_new.sh function init_l ...
- Openstack Ice-House 版本号说明--之中的一个 NOVA
OpenStack Icehouse在4.17正式公布,看了下release note,发现改变不小,说明openstack还是在高速发展中,有不少新的特性增加,也有些小的剔除.以下就我所关注的项目做 ...
- android之TabWidget选项卡
1 概览 l TabWidget与TabHost.tab组件一般包括TabHost和TabWidget.FrameLayout,且TabWidget.FrameLayout属于TabHost. l ...
- GUI编程笔记(java)04:GUI(HelloWorld)窗体案例
1.Frame 在JAVA中,Frame是一种控件,可作为父窗体加载其他swing控件.案例: package cn.itcast_01; import java.awt.Frame; public ...
- Android(java)学习笔记194:ListView编写步骤(重点)
1.ListView在我们的手机android编写程序中使用是十分广泛的,比如如下图中 短信 和 手机设置 都是ListView的效果: 手机设置: 短信: 2.正因为这 ...
- Jquery 限制文本框输入字数【转】
<script type="text/javascript" src="js/jquery.min.js" ></script> < ...
- java Junit 测试中异常处理
错误提示: junit.framework.AssertionFailedError: No tests found in错误解决办法 用junit Test运行后,出现如下的错误:junit.fra ...
- iOS 此证书的签发者无效
1.先检查Apple Worldwide Developer Relations Certification Authority Intermediate Certificate证书是否过期,该证书过 ...
- Java程序实现导出Excel,支持IE低版本
来博客园两年多了,最近才开通了微博,因为懒所以也一直没有写东西,今天想整理一下自己前段时间遇到的一个导出的问题. 因为项目的需求,要做一部分导出功能.开始的时候用的公司的导出,但是很奇怪有部分模块导出 ...