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 ...
随机推荐
- DDos攻击篇
DDoS(Distributed Denial of Service,分布式拒绝服务)攻击的主要目的是让指定目标无法提供正常服务,甚至从互联网上消失,是目前最强大.最难防御的攻击之一. 1.1. SY ...
- hdoj--3072--Intelligence System(scc+缩点+数据去重)
Intelligence System Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Othe ...
- Node.js:Web 模块
ylbtech-Node.js:Web 模块 1.返回顶部 1. Node.js Web 模块 什么是 Web 服务器? Web服务器一般指网站服务器,是指驻留于因特网上某种类型计算机的程序,Web服 ...
- virtualbox 安装虚拟机(centos7) 并映射本地文件夹至虚拟机(增强工具)
一.安装环境 操作系统:windows10 virtualbox: 5.2.20 (在安装virtualbox 时可能需要 进入BIOS 设置虚拟化系统启动) centos7:http://mirro ...
- Mysql数据的增删改
插入数据 INSERT 更新数据 UPDATE 删除数据 DELETE 再来回顾一下之前我们练过的一些操作,相信大家都对插入数据.更新数据.删除数据有了全面的认识.那么在mysql中其实最重要的不 ...
- damn selenium
Selenium+Python [ˈpaɪθən] 0.Selenium安装 pip install selenium 1.打开了浏览器,后边什么都不干了 需要将浏览器驱动放置在环境变量的目录下. 2 ...
- 第一天:java与mysql的连接工具类
第一天:java与mysql的连接工具类 java最新版马上就要收费,这无疑是这门语言的衰败起始,毕竟在中国收费便难发展,例如c#,但是毕业设计已经选好用java来写一个动态网站, 这已经是一个事实, ...
- HTTP获取信息的四种方式
HTTP 从网络获取信息的四种方式 GET GET指代你在浏览器中输入网址,浏览网站时做的事.例如,我们使用 http://www.baidu.com 的时候,可以将GET想象成他说:"hi ...
- Google浏览器“无法添加来自此网站的应用、扩展程序和应用脚本”的解决办法
原文链接:https://blog.csdn.net/Fan_Weibin/article/details/80402790 解决方法如下: 在桌面找到Google Chrome图标→右击属性→在快捷 ...
- 使用Caffe预测遇到的问题
1. 在使用网络预测图像时, prediction = net.predict( [input_image] ) 出现: net.image_dims[0] 不是整数情况, (2).甚至以为np.ze ...