HDU3177 贪心

时间:2022-12-30 12:12:06

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
HDU3177 贪心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&colon; &lbrack;Usaco2007 Dec&rsqb;队列变换 &lbrack;后缀数组 贪心&rsqb;

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

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

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

  4. HDOJ 1009&period; Fat Mouse&&num;39&semi; Trade 贪心 结构体排序

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

  5. BZOJ 1691&colon; &lbrack;Usaco2007 Dec&rsqb;挑剔的美食家 &lbrack;treap 贪心&rsqb;

    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 均分纸牌&lpar;贪心&rpar;

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

  9. 【BZOJ1623】 &lbrack;Usaco2008 Open&rsqb;Cow Cars 奶牛飞车 贪心

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

随机推荐

  1. Maven私有仓库搭建和使用

    下载和安装 下载地址: http://www.sonatype.com/nexus-repository-oss 安装: Linux版的无需安装,直接解压即可,然后进入bin目录下,运行./nexus ...

  2. python操作系统环境变量

    获取整个系统变量的方法是os.environ,这是一个os的class类型,使用的时候可以转换为字典类型 environ_value = dict(os.environ) 这样就可以看所有的key,e ...

  3. 关于帧中继和ppp的补充笔记

    帧中继: · 两个设备都要启用 帧中继功能, 否则是不能 ping通的 · 两个设备上的接口serial要 no shutdown · · 一定要配置dlci地址(号). 否则就不能起来pvc 可以 ...

  4. SpringBoot集成jsp(附源码)&plus;遇到的坑

    1.大体步骤 (1)       创建Maven web project: (2)       在pom.xml文件添加依赖: (3)       配置application.properties支持 ...

  5. Quartz 第六课 CronTrigger(官方文档翻译)

    CronTriggers使用的频率比SimpleTrigger跟高.如果需要schedule 中触发Job的方式类似于日历的形式而不是一个确定的是时间间隔,那就需要使用CronTrigger. 对于C ...

  6. DELPHI 多线程

    效果不正确 unit Unit1; interface uses   Windows, Messages, SysUtils, Variants, Classes, Graphics, Control ...

  7. 利用CryptoStream进行加密解密

    public class DBSecurity { //sKey sIV这两个自己随意设定,不能外泄 private const string sKey = "11,22,33,43,34, ...

  8. BLSTM的训练算法、解码算法以及模型的改进

    摘要 BLSTM解码时,解码器需要等待整个音频到达后才开始解码,因为时间反方向的前向传播需要末尾的历史信息.BLSTM这一延时问题使其不适用与实时语音识别.context-sensitive-chun ...

  9. 18 subprocess模块&lpar;跟操作系统交互&rpar;

    1.基本概念介绍 我们经常需要通过Python去执行一条系统命令或脚本,系统的shell命令是独立于你的python进程之外的, 每执行一条命令,就是发起一个新进程,通过python调用系统命令或脚本 ...

  10. 使用 win10 的库来组织自己的同类文件

    库相当于虚拟目录,可以把不同的文件夹包含起来. 找起东西来不用东奔西跑了...