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. javascript之iframe
  2. 剑指offer python版 找出数组中重复的数字
  3. ROS系统 服务数据的定义与使用
  4. 电脑动态屏保_8款电脑软件,每一款都能让你的电脑更好用
  5. 一图看懂云栖大会「云原生」重磅发布
  6. Java中Comparable和Comparator接口区别分析
  7. 实际工作中,一个完整的可视化大屏项目有哪些步骤?
  8. 用户管理实用命令(第二版)
  9. mac 建立软链接_MAC要倒闭了吗?正装口红80块,生姜高光105,让爱老师存点钱吧!...
  10. 蓝桥杯 ADV-134算法提高 校门外的树
  11. matlab中最好用的滤波函数,matlab中滤波函数
  12. 2021-05-09 matlab归一化和反归一化函数——mapminmax
  13. ANSI-美国国家标准学会
  14. xml中外部引用DTD文档
  15. python魔方方法
  16. 微信公众号使用:微信公众平台企业类型的微信认证申请流程
  17. 月薪超1.6万美元!对冲基金实习生也内卷
  18. [转]人生多磨难 句句皆精华
  19. 使用python爬取中国电影票房数据并写入csv文件
  20. 平均股价的时间序列图形_每年的平均股价怎么算

热门文章

  1. vscode更改edge浏览器
  2. 百度百科词条中对PX的描述竟是“剧毒
  3. oracle 聚合函数 日期,Oracle日期函数/字符函数/数字函数/转换函数/聚合函数
  4. ARM汇编指令_u-boot
  5. 077. Zookeeper 集群相关信息
  6. 微软Bing版ChatGPT表明想做人类,并且对纽约时报专栏作家表达爱意
  7. 2020-2021Android开发岗面经合集:90% 成功率的BAT Offer 收割机是怎样练成的!(内附快手,陌陌,小米面经)
  8. Mybatis环境搭建(仅供参考)
  9. 自然语言处理(NLP)设计的几个层次
  10. linux-acls-给一个目录添加用户