Crixalis's Equipment

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 5122    Accepted Submission(s): 2089

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

题意:向体积为V的洞穴里存放n件装备,在移动装备需要B[i]空间,移动后V减少A[i],问能不能放入所有装备

思路:按B[i]-A[i]排序

#include<stdio.h>
#include<algorithm>
using namespace std;
struct node{int a,b;
}num[10005];
int cmp(node x,node y)
{return x.b-x.a > y.b-y.a;
}
int main()
{int t;scanf("%d",&t);while(t--){int n,v;int flag=0;scanf("%d%d",&v,&n);for(int i=0;i<n;i++){scanf("%d%d",&num[i].a,&num[i].b);}sort(num,num+n,cmp);for(int i=0;i<n;i++){if(num[i].b>v){flag=1;break;}v-=num[i].a;}if(flag==1){printf("No\n");}else printf("Yes\n");}return 0;
}

HDU 3177 Crixalis's Equipment (贪心)相关推荐

  1. HDU ACM 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 贪心

    该题给定一个容器的体积,以及N个物品,每个物品有其要求的最少空间以及实际所占的空间 . 要我们判断是否可以把所有的物品全部放在里面,当然如果能够放进去也是需要一定的顺序的.最好的放置方法就是每次将物品 ...

  3. HDU 2795 Billboard (线段树+贪心)

    HDU 2795 Billboard (线段树+贪心) 手动博客搬家:本文发表于20170822 21:30:17, 原地址https://blog.csdn.net/suncongbo/articl ...

  4. HDU.3177Crixalis's Equipment(贪心)

    题目来源:3177 题目分析:一只蝎子要搬动一堆装备到一个容量为V的洞里面,每个装备有两个属性,一个是固有体积A,放置之后洞的剩余空间就会减少A,一个是移动体积B,只有当体积B小于等于当前洞的剩余体积 ...

  5. hdu 3177贪心

    #include<stdio.h>/*只能按这种形式排序单纯一种形式是不对的,按ai排序 20 2 1 1 10 20 按bi排序 20 2 5 17 1 16 都是不对的 二a.u+b. ...

  6. HDU 5281 Senior's Gun (贪心)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5281 贪心题目,但是看看我的博客里边相关贪心的题解实在是少的可怜,这里就写出来供大家一起探讨. 题意还 ...

  7. hdu 6203 ping ping ping(贪心+树状数组+dfs序)

    题目链接:hdu 6203 ping ping ping 题意: 给你一棵n+1个节点树,现在有q条路径不通,问你最少有多少个节点坏掉了. 题解: 考虑贪心,对这q条路径求一下lca,按照lca的深度 ...

  8. hdu 2546 饭卡【贪心+01背包基础题】

    链接: http://acm.hdu.edu.cn/showproblem.php?pid=2546 http://acm.hust.edu.cn/vjudge/contest/view.action ...

  9. HDU 2546 饭卡(贪心+DP)

    题目链接 几个月之前做的一个题了,开始想时就看出应该是个01背包问题,又发现不太一样,貌似应该是有种贪心策略,把最大的挑出来最后还有5块钱的再买,剩下的体积用01背包去求最优选择,当时WA了3次,以为 ...

最新文章

  1. Virtio:针对 Linux 的 I/O 虚拟化框架
  2. leetcode 110. 平衡二叉树
  3. 网上书店例子(JSP和JavaBean)
  4. elasticsearch_script_02
  5. 转---猫大叫一声,所有的老鼠都开始逃跑,主人被惊醒 [观察者模式]
  6. YAML_12 批量创建用户,分别设置用户组
  7. centos7 里面dump_centos7使用lldb调试netcore应用转储dump文件
  8. 电脑没有摄相头,使用安卓或IOS旧手机替代摄相头
  9. office2013 安装易用宝不成功
  10. 中国移动云MAS平台发送普通短信
  11. 教师公开课教学课件PPT模板
  12. Python 数据科学入门教程:Matplotlib
  13. spring boot入门 -- 介绍和第一个例子
  14. 平均风向计算中对于风向角的判断
  15. ubuntu从19.04升级到20.04后五笔一直不能输入中文,解决方法
  16. C. Yet Another Broken Keyboard--------思维
  17. Note For Linux By Jes(7)-学习 shell scripts
  18. SpringMVC @RequestBody问题:Unrecognized field , not marked as ignorable
  19. 小米盒子进入android,当北市场教您如何使用小米盒子安装非Android大型游戏
  20. 9 月编程语言推荐榜:C、Java 和 Python 争夺第一

热门文章

  1. Java中StringBuilder清空数据方法比较
  2. win10新无线网无法连接服务器,Win8无线网络无法连接怎么办?
  3. 计算机SP与SSP什么岗位,校招sp和ssp是什么意思
  4. 玩转树莓派(一):树莓派更换国内源、设置中文显示及输入法
  5. [251]Redis Scard 命令、Spop 命令
  6. Windows Server 2008 R2 常用设置
  7. 数据结构与算法--符号图
  8. 小满OKKI CRM对接金蝶云星空案例
  9. 下一代无线局域网演进趋势
  10. 12306用户数据泄露:有人订票被恶作剧退掉(转)