Crixalis's Equipment

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 1854    Accepted Submission(s): 770

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
 

#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
struct Node
{
    int a;
    int b;
    int c;
}p[1111];
bool cmp(Node x,Node y)
{
    return x.c>=y.c;
}
int main()
{
    int T;
    scanf("%d",&T);
while(T--)
{
    memset(p,0,sizeof(p));
    int n,v;
    scanf("%d%d",&v,&n);
    for(int i=0;i<n;i++)
    {
        scanf("%d%d",&p.a,&p.b);
        p.c=p.b-p.a;
    }
    sort(p,p+n,cmp);
    int OK=1;
    for(int i=0;i<n;i++)
    {
        if(v>=p.b)
        {
            v-=p.a;
        }
        else
        {
            OK=0;
            break;
        }
    }
    if(OK)
        puts("Yes");
    else
        puts("No");
}
    return 0;
}

HDOJ 3177 Crixalis&#39;s Equipment的更多相关文章

  1. 杭电 3177 Crixalis&#39;s Equipment

    http://acm.hdu.edu.cn/showproblem.php? pid=3177 Crixalis's Equipment Time Limit: 2000/1000 MS (Java/ ...

  2. HDU 3177 Crixalis&#39;s Equipment(贪婪)

    主题链接:http://acm.hdu.edu.cn/showproblem.php? pid=3177 Problem Description Crixalis - Sand King used t ...

  3. hdu 3177 Crixalis&#39;s Equipment

    Crixalis's Equipment Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Oth ...

  4. Hdu 3177 Crixalis's Equipment

    Crixalis's Equipment Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Oth ...

  5. HDU ACM 3177 Crixalis's Equipment

    Crixalis's Equipment Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Oth ...

  6. 【hdu 3177 Crixalis's Equipment】 题解

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3177 \(describe\): 有一个山洞,山洞的容积最大为\(v\).现在你有\(n\)个物品,这 ...

  7. HDU 3177 Crixalis's Equipment (贪心,差值)

    题意:判断 n 件物品是否可以搬进洞里,每件物品有实际体积A和移动时的额外体积 B . 析:第一反应就是贪心,一想是不是按B从大到小,然后一想,不对,比如体积是20,第一个 是A=11, B=19.第 ...

  8. HDOJ 3966 Aragorn&#39;s Story

    树链拆分+树阵 (进入坑....) Aragorn's Story Time Limit: 10000/3000 MS (Java/Others)    Memory Limit: 32768/327 ...

  9. hdoj 4932 Miaomiao&#39;s Geometry 【暴力枚举】

    题意:在一条直线上有n个点.取一长度差为x的区间. 规定点必须是区间的端点. 让你找出来最大的x 策略:rt 分析可得:两个相邻点之间的区间要么是两个点的差,要么就是两个点的差的一半,那我们就简单枚举 ...

随机推荐

  1. Eclipse 4.6 Neon, could not create the java virtual machine

    下了eclipse 4.6,打开报错:could not create the java virtual machine. a fatal exception has occurred. 命令行用 e ...

  2. Android WebView代理设置方法(API10~21适用)

    最近碰到个需求需要在APP中加入代理,HttpClient的代理好解决,但是WebView碰到些问题,然后找到个API10~API21都通用的类,需要用的同学自己看吧,使用方法,直接调用类方法setP ...

  3. jpg图片在IE6、IE7和IE8下不显示解决办法

    坑人的IE浏览器,花了我一个小时才找到原因. 原因:IE内核不能渲染CMYK模式的jpg图片,需要转换为RGB模式. 在photoshop里点击菜单栏—图像—RGB模式就行了 引用:http://lg ...

  4. "奇葩家园“之genymotion工具篇

    genymotion 简直就是android开发者的福音,比android内置的模拟器不知道快多少, 具体的安装可以参考如下: 1.登陆官方网站,必须先注册 https://www.genymotio ...

  5. 打造一款属于自己的web服务器——开篇

    JVM总结慢慢来吧,先插播一篇水文,来介绍下最近业余一直在写的一个小项目——easy-httpserver(github).适合新手学习,大神们路过即可^_^. 一.这是个什么玩意? easy-htt ...

  6. iOS学习之UITabBarController

    一.标签视图控制器——UITabBarController 1.UITabBarController的继承关系: @interface UITabBarController : UIViewContr ...

  7. 微信扫码支付asp.net(C#)实现步骤

    支付提交页面: [HttpPost] public ActionResult index(decimal amount) { //生成订单10位序列号,此处用时间和随机数生成,商户根据自己调整,保证唯 ...

  8. openSUSE install failed

    install openSUSE 13.1 with vmware play (version 6.0.0)  calling the yast module 'inst_autoinit has f ...

  9. Entity Framework 学习第二天

    今天记录的内容不多,只是简单用一下Model first,新建项目,然后添加新建项,选择数据中的ado.net实体数据模型 这次我们选择空模型,然后右键,新增,实体 在这项demo中我打算建两个数据实 ...

  10. MVC3+中 ViewBag、ViewData和TempData的使用和区别

    在MVC3开始,视图数据可以通过ViewBag属性访问,在MVC2中则是使用ViewData.MVC3中保留了ViewData的使用.ViewBag 是动态类型(dynamic),ViewData 是 ...