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" ...
随机推荐
- db2记录去重
--查出二码,归档日期,借据号重复的数据的条数 select default_index_item_id,record_date,index_yxdk_dkjjh,min(sys_org_id),ma ...
- Cmake的介绍和使用 Cmake实践
Cmake的介绍和使用 Cmake实践http://www.cppblog.com/Roger/archive/2011/11/17/160368.html
- windows下通过navicat for mysql连接centos6.3-64bit下的MySQL数据库
一.centos下MySQL安装 按照命令依次安装以下文件: mysql-devel 开发用到的库以及包含文件 mysql mysql 客户端 mysql-server 数据库服务器 yum inst ...
- Maven_真的需要吗?
1.真的需要吗? Maven 是干什么用的?这是很多同学在刚开始接触 Maven 时最大的问题.之所以会提出这个问题,是因为即使不使用 Maven 我们仍然可以进行 B/S 结构项目的开发.从表述层. ...
- ACM数论常用知识完全解读
此版本纯属扯淡....... 一个一个来起.
- ERROR 1045 (28000)
mysql登陆出现这个错误时,解决方法如下: 1. 修改mysql配置文件,增加 skip-grant-tables 如我的机器是linux 所以要修改/etc/mysql/my.cnf 在mysql ...
- git SSL certificate problem: unable to get local issuer certificate
cmd 命令行中输入 git config --global http.sslVerify false 之后再进行操作
- pg_dump: [archiver (db)] connection to database “dbase” failed: FATAL: Peer authentication failed for user “postgres”
"Peer authentication" means that it's comparing your database username against your Linux ...
- 错误代码: 1045 Access denied for user 'skyusers'@'%' (using password: YES)
1. 错误描写叙述 GRANT ALL PRIVILEGES ON *.* TO root@"%" IDENTIFIED BY "."; 1 queries e ...
- wpf slider进度条的样式模板,带有进度颜色显示
效果图: 仅仅需在前台加上这段代码就可以: <UserControl.Resources> <!--笔刷--> <LinearGradientBrush x:Key=&q ...