HDU3177 贪心
Crixalis's Equipment
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 3957 Accepted Submission(s): 1625

- 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.
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.
20 3
10 20
3 10
1 7
10 2
1 10
2 11
No
lcy | We have carefully selected several similar problems for you: 1789 1051 1053 1045
代码:
/*
应该先放实际体积小而需要的体积大的,所以按照差值由大到小排序
*/
#include<iostream>
#include<string>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<queue>
#include<stack>
using namespace std;
int t,v,n;
struct eq
{
int a,b;
}e[];
bool cmp(eq x,eq y)
{
return x.b-x.a>y.b-y.a;
}
int main()
{
scanf("%d",&t);
while(t--)
{
scanf("%d%d",&v,&n);
for(int i=;i<n;i++)
{
scanf("%d%d",&e[i].a,&e[i].b);
}
sort(e,e+n,cmp);
for(int i=;i<n;i++)
{
if(v<e[i].b)
{
v=-;
break;
}
v-=e[i].a;
}
if(v==-)
printf("No\n");
else printf("Yes\n");
}
return ;
}
HDU3177 贪心的更多相关文章
- 【贪心】【HDU3177】 搬家问题
</pre><pre name="code" class="cpp">#include <iostream> #includ ...
- BZOJ 1692: [Usaco2007 Dec]队列变换 [后缀数组 贪心]
1692: [Usaco2007 Dec]队列变换 Time Limit: 5 Sec Memory Limit: 64 MBSubmit: 1383 Solved: 582[Submit][St ...
- HDOJ 1051. Wooden Sticks 贪心 结构体排序
Wooden Sticks Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) To ...
- HDOJ 1009. Fat Mouse' Trade 贪心 结构体排序
FatMouse' Trade Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) ...
- BZOJ 1691: [Usaco2007 Dec]挑剔的美食家 [treap 贪心]
1691: [Usaco2007 Dec]挑剔的美食家 Time Limit: 5 Sec Memory Limit: 64 MBSubmit: 786 Solved: 391[Submit][S ...
- 【Codeforces 738D】Sea Battle(贪心)
http://codeforces.com/contest/738/problem/D Galya is playing one-dimensional Sea Battle on a 1 × n g ...
- 【BZOJ-4245】OR-XOR 按位贪心
4245: [ONTAK2015]OR-XOR Time Limit: 10 Sec Memory Limit: 256 MBSubmit: 486 Solved: 266[Submit][Sta ...
- code vs 1098 均分纸牌(贪心)
1098 均分纸牌 2002年NOIP全国联赛提高组 时间限制: 1 s 空间限制: 128000 KB 题目等级 : 黄金 Gold 题解 题目描述 Description 有 N 堆纸牌 ...
- 【BZOJ1623】 [Usaco2008 Open]Cow Cars 奶牛飞车 贪心
SB贪心,一开始还想着用二分,看了眼黄学长的blog,发现自己SB了... 最小道路=已选取的奶牛/道路总数. #include <iostream> #include <cstdi ...
随机推荐
- linux下vim配置以及一些常用的快捷键
一些常用的vim编辑器快捷键: h」.「j」.「k」.「l」,分别控制光标左.下.上.右移一格. 按「ctrl」+「b」:屏幕往“后”移动一页. 按「ctrl」+「f」:屏幕往“前”移动一页. 按「c ...
- nginx配置文件nginx.conf
#定义Nginx运行的用户和用户组user www www; #nginx进程数,建议设置为等于CPU总核心数.worker_processes 8; #全局错误日志定义类型,[ debug | in ...
- Android 蹲坑的疑难杂症集锦一
各位看官老爷子你们好,我就是那个挖坑不埋,还喜欢开新矿的小喵同志. 问大家一个问题,在Github上找项目的时候,看到中文简介说明你们是不是觉得这个项目很low不屑一顾? 最近朋友无意中说,在Gith ...
- loadrunner实现浮点型数据转换成字符串
ftoa(float floatNum, char *convFloatString) { char new[10]; float number,dTemp,temp_val; int base, f ...
- 使用Eclipse将Web项目打Jar包方法
1.对下载.安装和运行Eclipse,就不再说了: 2.找到待打包项目: 3.右键,Export-->Export: 4.选择,Jar: 5.按如图操作: 6.完成后:
- mysql LAST_INSERT_ID 使用与注意事项
在使用MySQL时,若表中含自增字段(auto_increment类型),则向表中insert一条记录后,可以调用last_insert_id()来获得最近insert的那行记录的自增字段值 $mdb ...
- JS实现有点炫的图片展示效果-图片解体和组合
经过4个月的努力学习,迎来了进入市场的最后一个学习项目.自己模仿了一个图片展示效果,用在了项目中,感觉挺炫的.在这里分享一下,希望大家喜欢~! bomb-showImg : 在线演示http://ru ...
- delphi override、overload、reintroduce的区别-0613.txt
http://blog.csdn.net/honglixx/article/details/3624934 1.override overload reintroduce的中文叫法是什么? overr ...
- 转:delphi 删除指定文件夹下所有文件
function TFtpContentThd.DeleteDirectory(NowPath: string): Boolean; var search: TSearchRec; ret: inte ...
- JS(ajax笔记)
简介:AJAX = Asynchronous JavaScript and XML(异步的 JavaScript 和 XML). AJAX 不是新的编程语言,而是一种使用现有标准的新方法,是与服务器交 ...