hdu 3177 Crixalis's Equipment
Crixalis's Equipment

living habit of a scorpion like living underground and digging holes.
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.
equipment respectively. The next N lines contain N pairs of integers: Ai and Bi.
0<T<= 10, 0<V<10000, 0<N<1000, 0 <Ai< V, Ai <= Bi < 1000.
2 20 3
10 20
3 10
1 7 10 2
1 10
2 11
Yes
No
停放体积 移动体积
第一件物品 a1 b1
第二件物品 a2 b2
如果这两件物品的移动体积都不大于洞的体积V
a1+b2为先放第一件物品 后放第二件物品的最大瞬时体积
a2+b1为先放第二件物品 后放第一件物品的最大瞬时体积
我们应该选择a1+b2和a2+b1中比較小的先放.
如果n件物品的移动体积都不大于洞的体积V(如果有大于的 那么结果必定是NO)
将N件物品依照a1+b2<a2+b1进行排序,然后依次放入洞中。即依照差值从大到小放入洞中.
#include<stdio.h>
#include<iostream>
#include<algorithm>
using namespace std; struct node
{
int x,y;
}p[10005]; bool cmp(node a,node b) // 差值排序
{
return (a.y-a.x)>(b.y-b.x);
} int main ()
{
int t,n,m,i,j;
int flag;
scanf("%d",&t);
for(i=0;i<t;i++)
{
scanf("%d%d",&n,&m);
for(j=0;j<m;j++)
scanf("%d%d",&p[j].x,&p[j].y);
sort(p,p+m,cmp);
flag=1;
for(j=0;j<m;j++)
{
if(p[j].y>n)
{
flag=0;
break;
}
n-=p[j].x;
}
if(flag) printf("Yes\n");
else printf("No\n");
}
return 0; }
hdu 3177 Crixalis's Equipment的更多相关文章
- 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 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 \(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 3966 Aragorn's Story(树链剖分+树状数组)
pid=3966" target="_blank" style="">题目链接:hdu 3966 Aragorn's Story 题目大意:给定 ...
- HDU 3966 Aragorn's Story(树链剖分)
HDU Aragorn's Story 题目链接 树抛入门裸题,这题是区间改动单点查询,于是套树状数组就OK了 代码: #include <cstdio> #include <cst ...
随机推荐
- HDU 1257(最小拦截系统)
Description 某国为了防御敌国的导弹袭击,发展出一种导弹拦截系统.但是这种导弹拦截系统有一个缺陷:虽然它的第一发炮弹能够到达任意的高度,但是以后每一发炮弹都不 能超过前一发的高度.某天,雷达 ...
- Hadoop MapReduce编程 API入门系列之wordcount版本3(七)
这篇博客,给大家,体会不一样的版本编程. 代码 package zhouls.bigdata.myMapReduce.wordcount3; import java.io.IOException; i ...
- maven nexus memory optimization
#链接地址:https://help.sonatype.com/repomanager3/system-requirements#filehandles While starting Nexus I ...
- 1.Ventuz 介绍
Ventoz能做什么? Ventuz是一款实时图文包装内容创作.制作和播出控制软件.Ventuz专注于高端视听内容的制作,包括交互展示和大型活动.视频墙.广播电视在线包装及演播室舞台及灯光控制等领域. ...
- JavaScript实现数字时钟功能
<html> <head> <meta charset="utf-8"> <title>无标题文档</title> &l ...
- List 常用方法解析
1.Count属性 (获得List中元素数目) 2.Add( ) 在List中添加一个对象的公有方法 3.AddRange( ) 公有方法,在List尾部添加实现了ICollection接口的多个元素 ...
- java 简单工厂模式实现
简单工厂模式:也可以叫做静态工厂方法,属于类创建型模式,根据不同的参数,返回不同的类实现. 主要包含了三个角色: A.抽象产品角色 一般用接口 或是 抽象类实现 B.具体的产品角色,具体的类的实现 C ...
- Windows Phone 编程: 摇一摇 效果
Step 1: 下载摇晃手势开发库 http://create.msdn.com/en-us/edu ... ake_Gesture_LibraryStep 2: 解压后进入 ShakeGesture ...
- PHP在Linux的Apache环境下乱码解决方法
在windows平台编写的php程序默认编码是gb2312 而linux和apche默认的编码都是UTF-8 所以windows平台编写的php程序传到linux后,浏览网页中文都是乱码. 如果手工将 ...
- 信息检索及DM必备知识总结:luncene
原文链接:http://blog.csdn.net/htw2012/article/details/17734529 有少量修改!如有疑问,请访问原作者. 一:信息检索领域: 信息检索和网络数据领域( ...