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. Go:字符串操作

    Package strings:https://golang.google.cn/pkg/strings/ package main import ( "fmt" "st ...

  2. python3 的range

    1. range(3):从0到2: 2. range(3,10,2):从3到10,隔一个数显示一个: 3.list(range(3,10,-2):结果为空: 4. S[::2] : 同隔一个数显示一个 ...

  3. 10.3andXE7的DEVExpress18.2.1记录备查

    记录备查: win10 DEVExpress18.2.1用DevExpressVCL一键编译安装工具_v10.3.2 - 2018-12-12.exe(包括help,备份...升级系统不用重新安装控件 ...

  4. EasyUI Datagrid的简单使用

    此前同样写过EasyUI Datagrid的demo,好记性不如烂笔头,何况记性也不是那么好,赶紧记录一下.照搬上一篇EasyUI Tree的格式. 实现效果:获取数据库表的数据,在EasyUI Da ...

  5. Java Web学习总结(32)——Java程序员最亲睐的Web框架

    这一次,我们要讨论的是web框架. 只有少数几种语言像Java一样提供了各种各样的web框架,上面的统计图就是一个证据.下面是其他开发者所使用web框架列表: spring MVC/Spring Bo ...

  6. HDU 1325 拓扑排序

    根据题目所给的3个不符合情况的条件,一个个判断图是否符合这3个条件即可 1.不能出现内部环,拓扑排序判断 2.不能有超过1个点的入度为0,因为只有一个树根 3.每个点最多一个入度 这里要注意的一点是这 ...

  7. [luoguP1005] 矩阵取数游戏(DP + 高精度)

    传送门 和奶牛那个题很像,每一行状态互不影响,也就是求 n 遍DP 不过高精度非常恶心,第一次写,调了我一上午. ——代码 #include <cstdio> #include <c ...

  8. codevs3410 别墅房间

    题目描述 Description 小浣熊松松到他的朋友家别墅去玩,发现他朋友的家非常大,而且布局很奇怪.具体来说,朋友家的别墅可以被看做一个N*M的矩形,有墙壁的地方被标记为’#’,其他地方被标记为’ ...

  9. SystemTapでMySQL 5.5のDisk I/Oを分析する

    http://d.hatena.ne.jp/sh2/20111121 2010年1月の記事SystemTapでMySQLのDisk I/Oを分析するの続きです.以前作成したSystemTapスクリプト ...

  10. ubuntu How do I configure proxies without GUI?

    想法:  我的想法是想是一台国内的 ubuntu 云主机可以通过另外一台在国外(新加坡)的服务器 ,来实现可以访问 google ,哈哈,比较好查资料:) 下面的做法 去修改 /etc/environ ...