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

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
 
Source
 
Recommend

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 贪心的更多相关文章

  1. 【贪心】【HDU3177】 搬家问题

    </pre><pre name="code" class="cpp">#include <iostream> #includ ...

  2. BZOJ 1692: [Usaco2007 Dec]队列变换 [后缀数组 贪心]

    1692: [Usaco2007 Dec]队列变换 Time Limit: 5 Sec  Memory Limit: 64 MBSubmit: 1383  Solved: 582[Submit][St ...

  3. HDOJ 1051. Wooden Sticks 贪心 结构体排序

    Wooden Sticks Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) To ...

  4. HDOJ 1009. Fat Mouse' Trade 贪心 结构体排序

    FatMouse' Trade Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) ...

  5. BZOJ 1691: [Usaco2007 Dec]挑剔的美食家 [treap 贪心]

    1691: [Usaco2007 Dec]挑剔的美食家 Time Limit: 5 Sec  Memory Limit: 64 MBSubmit: 786  Solved: 391[Submit][S ...

  6. 【Codeforces 738D】Sea Battle(贪心)

    http://codeforces.com/contest/738/problem/D Galya is playing one-dimensional Sea Battle on a 1 × n g ...

  7. 【BZOJ-4245】OR-XOR 按位贪心

    4245: [ONTAK2015]OR-XOR Time Limit: 10 Sec  Memory Limit: 256 MBSubmit: 486  Solved: 266[Submit][Sta ...

  8. code vs 1098 均分纸牌(贪心)

    1098 均分纸牌 2002年NOIP全国联赛提高组  时间限制: 1 s  空间限制: 128000 KB  题目等级 : 黄金 Gold 题解   题目描述 Description 有 N 堆纸牌 ...

  9. 【BZOJ1623】 [Usaco2008 Open]Cow Cars 奶牛飞车 贪心

    SB贪心,一开始还想着用二分,看了眼黄学长的blog,发现自己SB了... 最小道路=已选取的奶牛/道路总数. #include <iostream> #include <cstdi ...

随机推荐

  1. loj 1377 (bfs)

    题目链接:http://lightoj.com/volume_showproblem.php?problem=1377 思路:这道题只要处理好遇到"*"这种情况就可以搞定了.我们可 ...

  2. 自己yy的Splay

    #include <iostream> #include <cstdio> #include <queue> using namespace std; ; stru ...

  3. 获取APK签名

    获取apk签名工具类 import android.content.Context; import android.content.pm.PackageInfo; import android.con ...

  4. cf 106C

    题目链接:http://vjudge.net/contest/139376#problem/E 题意看注释就能懂了,求能获得的最大价值. 代码: #include<iostream> #i ...

  5. 仓库如何盘点 打印扫描一体PDA盘点机提升库存盘点效率

    仓库盘点是对仓储货品的收发结存等活动进行有效控制,保证仓储货品完好无损.帐物相符,确保生产正常进行,规范公司物料的盘点作业.盘点需人工操作,费时费力,PDA盘点机的出现大幅提升了盘点效率,减轻了工作人 ...

  6. css3 -- 颜色与不透明度

    1.opacity: opacity的值会被它的所有子元素继承,也就是说不可能让一个元素比他的父元素更加不透明,但你可以让他变得更透明点 Firefox  Webkit  Opera支持,注意IE 2 ...

  7. 优先队列 UVA 11997 K Smallest Sums

    题目传送门 题意:训练指南P189 分析:完全参考书上的思路,k^k的表弄成有序表: 表1:A1 + B1 <= A1 + B2 <= .... A1 + Bk 表2:A2 + B1 &l ...

  8. Sprint回顾_团队听诊器

  9. 【Oracle】在WIN NT 64位环境下安装win64_11gR2_database。并用PL/SQL连接

    因为现在大多数服务器环境均为64位环境,而且有一部分使用的windows server的环境,在此做了一番小研究,如何在64位环境下安装oracle11g_64bit服务端 (1)首先www.orac ...

  10. iOS之01-基本语法

    视频iOS是本人通过视频学习,初期并不是直接使用Xcode,而是在命令行下创建文件.打开文件.编译文件和运行文件. #import <Foundation/Foundation.h> in ...