hdu---3177 Crixalis's Equipment 根据 两个元素 之间的权衡进行排序
Crixalis's Equipment
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.
0<T<= 10, 0<V<10000, 0<N<1000, 0 <Ai< V, Ai <= Bi < 1000.
20 3
10 20
3 10
1 7
10 2
1 10
2 11
#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 根据 两个元素 之间的权衡进行排序的更多相关文章
- 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 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 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 ...
- DOM的小练习,两个表格之间数据的移动
本次讲的是两个表格之间数据的移动,左边的表格移动到右边,并且左边表格移动内容消失. <head> <meta http-equiv="Content-Type" ...
随机推荐
- 深入理解PHP之strpos
概述 在php中经常用 strpos 判断字符串是否在另一个字符串中存在, 本文介绍 strpos 函数及其实现. strpos应用 <?php /* strpos示例 */ // test e ...
- Q-criterion- definition and post-processing
Q-criterion Table of Contents 1. Q-Criterion 1.1. Q-criterion– Hunt, Wray & Moin 1988 1.2. Q cri ...
- 将网络图片转换为base64
public static function htmlPdf() { $img_path = Env::get('ROOT_PATH').'/public/images/wechat/user.jpg ...
- BZOJ 3993 Luogu P3324 [SDOI2015]星际战争 (最大流、二分答案)
字符串终于告一段落了! 题目链接: (bzoj) https://www.lydsy.com/JudgeOnline/problem.php?id=3993 (luogu) https://www.l ...
- Adobe AIR 代码签名证书使用指南
Symantec,Thawte,GlobalSign 签发的代码签名证书都可以签名AIR文件.如果您还没有代码签名证书,请联系易维信(EVTrust)购买Adobe AIR 代码签名证书. 1.签名工 ...
- 《Spring Boot 那些事》
<Spring Boot 那些事>----https://www.bysocket.com/?p=1124
- 此人牛b,学习榜样
http://liyangliang.me/about/ ------------------------------------------------------------2017年11月12日 ...
- 使用jconsole监控远程JVM
使用jconsole监控远程JVM 学习了:https://www.linuxidc.com/Linux/2015-02/113420.htm https://www.cnblogs.com/thin ...
- UDEV SCSI Rules Configuration for ASM in Oracle Linux 5 and 6
UDEV SCSI Rules Configuration for ASM in Oracle Linux 5 and 6 For Oracle Automatic Storage Manager ( ...
- iOS中的枚举:enum, NS_ENUM, NS_OPTIONS的使用区别
1.enum可以声明一般类型和位掩码(bitmasked)类型 例如: enum Test{// 一般枚举 TestA, TestB, TestC, }; enum{// 匿名枚举 TestA, Te ...