Crixalis's Equipment

Problem Description
Crixalis - Sand King used to be a giant scorpion(蝎子) in the deserts of Kalimdor. Though he's a guardian of Lich King now, he keeps the 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.

 
Input
The first line contains an integer T, indicating the number of test cases. Then follows T cases, each one contains N + 1 lines. The first line contains 2 integers: V, volume of a hole and N, number of 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.
 
Output
For each case output "Yes" if Crixalis can move all his equipment into the new hole or else output "No".
 
Sample Input
2

20 3
10 20
3 10
1 7

10 2
1 10
2 11

 
Sample Output
Yes
No
题意: 蝎子想搬家(洞穴)  然后因为有家具所以 所以挖洞的时候要考虑家具的 摆放     摆放家具的时候 家具会占用 a  个 空间  在将家具移动到 合适的位置的时候  需要b个空间   新家的空间v 和 家具的件数n  然后跟着n行   分别是 每件家具的 占用空间 和 移动空间  现在问你  能不能  将  这些 家具 移动到 新家   
因为有  移动空间 所以 问题就变得复杂了  .      但是核心思想还是     让 空间尽量慢的减少   在下一个家具没有移动进去之前要尽量的节省剩余空间  而且如果想移进去 剩余空间必须大于等于 家具的 占地空间和移动空间  排序的话 就按照      上个家具的占地空间+这个家具的移动空间  最小就行  (这样每次移动的时候  都会出现相同的状况(程序设计 找 长状态节点的思想))

 #include<stdio.h>
#include<algorithm>
using namespace std;
struct hole
{
int a,b; // 占地 为a 移动空间 为b
};
bool cmp(hole a,hole b)
{
if(a.a+b.b<a.b+b.a)
return ;
else
if(a.a+b.b==a.b+b.a)
return a.b>b.b;
else
return ; // 让上次的 已经占地的物品 和 这次的物品的移动空间 尽量小 .
}
int main()
{
int t,i,n,v;
hole a[];
scanf("%d",&t);
while(t--)
{
int flag=;
scanf("%d%d",&v,&n);
for(i=;i<n;i++)
scanf("%d%d",&a[i].a,&a[i].b);
sort(a,a+n,cmp);
for(i=;i<n;i++)
{
if(v>=a[i].a&&v>=a[i].b) // 剩下的 空间 大于等于 这次物品的 占地空间和 移动空间
{
v-=a[i].a;
}
else
{
flag=;
break;
}
}
if(flag)
printf("Yes\n");
else
printf("No\n");
}
return ;
}

hdu---3177 Crixalis's Equipment 根据 两个元素 之间的权衡进行排序的更多相关文章

  1. Hdu 3177 Crixalis's Equipment

    Crixalis's Equipment Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Oth ...

  2. 【hdu 3177 Crixalis's Equipment】 题解

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3177 \(describe\): 有一个山洞,山洞的容积最大为\(v\).现在你有\(n\)个物品,这 ...

  3. HDU 3177 Crixalis's Equipment (贪心,差值)

    题意:判断 n 件物品是否可以搬进洞里,每件物品有实际体积A和移动时的额外体积 B . 析:第一反应就是贪心,一想是不是按B从大到小,然后一想,不对,比如体积是20,第一个 是A=11, B=19.第 ...

  4. HDU ACM 3177 Crixalis's Equipment

    Crixalis's Equipment Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Oth ...

  5. hdu 3177 Crixalis&#39;s Equipment

    Crixalis's Equipment Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Oth ...

  6. HDU 3177 Crixalis&#39;s Equipment(贪婪)

    主题链接:http://acm.hdu.edu.cn/showproblem.php? pid=3177 Problem Description Crixalis - Sand King used t ...

  7. 杭电 3177 Crixalis&#39;s Equipment

    http://acm.hdu.edu.cn/showproblem.php? pid=3177 Crixalis's Equipment Time Limit: 2000/1000 MS (Java/ ...

  8. HDOJ 3177 Crixalis&#39;s Equipment

    Crixalis's Equipment Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Oth ...

  9. DOM的小练习,两个表格之间数据的移动

    本次讲的是两个表格之间数据的移动,左边的表格移动到右边,并且左边表格移动内容消失. <head>   <meta http-equiv="Content-Type" ...

随机推荐

  1. 微信小程序支付全问题解决

    这几天在做小程序的支付,没有用官方的SDK,这里就纯用官方的文档搞一发. * 注作者使用的PHP,不过支付流程都是这样 开发前必读 主要流程 小程序前端发送求参请求 接受请求封装 "统一下单 ...

  2. 洛谷 1339 [USACO09OCT]热浪Heat Wave

    [题解] 最短路.那么直接写dijkstra就好了. #include<cstdio> #include<algorithm> #include<cstring> ...

  3. codeforces 373 A - Efim and Strange Grade(算数模拟)

    codeforces 373 A - Efim and Strange Grade(算数模拟) 原题:Efim and Strange Grade 题意:给出一个n位的实型数,你可以选择t次在任意位进 ...

  4. python整数转ASCII码

    # *-* coding:utf-8 *-* import binascii data = [1441465642, 251096121, -870437532, -944322827, 647240 ...

  5. 洛谷——P1082 同余方程

    P1082 同余方程 题目描述 求关于 x 的同余方程 ax ≡ 1 (mod b)的最小正整数解. 输入输出格式 输入格式: 输入只有一行,包含两个正整数 a, b,用一个空格隔开. 输出格式: 输 ...

  6. Android GIS开发系列-- 入门季(4) GraphicsLayer的点击查询要素

    上一讲中我们学会了如何在MapView中添加Graphic要素,那么在百度或高德地图中,当我们点击要素时,会显示出相应的详细信息.在GraphicsLayer中也提供了这样的方法.下面我们来学习在Gr ...

  7. 转 java中5种创建对象的方法

    作为Java开发者,我们每天创建很多对象,但我们通常使用依赖管理系统,比如spring去创建对象.然而这里有很多创建对象的方法,我们会在这篇文章中学到. Java中有5种创建对象的方式,下面给出它们的 ...

  8. python-paramiko初体验

    什么pexpect.pxshll在paramiko面前都是浮云,重要的是paramiko支持windows. 小试牛刀 import paramiko paramiko.util.log_to_fil ...

  9. shell 例程 —— 解决redis读取稳定性

    问题背景: php读取线上redis数据,常常不稳定,数据响应时有时无. 解决方法:多次读取.每次读取全部上一次没读出的数据,直到全部获取. 本文实现用shell进行多次redis数据读取, 每次取出 ...

  10. Vim 经常使用快捷键及键盘图

    Vim经常使用的快捷键 h - 光标左移一个字符   j - 光标下移一个字符 k - 光标上移一个字符   l - 光标右移一个字符  下移15行 - 15j Ctrl + f - 屏幕向下移动一页 ...