杭电 3177 Crixalis's Equipment

http://acm.hdu.edu.cn/showproblem.php?pid=3177

Crixalis‘s Equipment

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)

Total Submission(s): 2562    Accepted Submission(s): 1056

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

AC代码:

<span style="font-size:18px;">#include<iostream>
#include<cstdio>
#include<algorithm> 

using namespace std;

struct Node
{
   int a,b;
   int c;
}s[1005];

bool cmp(Node a,Node b)
{
    return a.c>b.c;
}

int main()
{
    int T,V,N,i;
    scanf("%d",&T);
    while(T--)
    {
        scanf("%d%d",&V,&N);
        for(i=0;i<N;i++)
        {
            scanf("%d%d",&s[i].a,&s[i].b);
            s[i].c=s[i].b-s[i].a;
        }

        sort(s,s+N,cmp);

        for(i=0;i<N;i++)
        {
            if(s[i].b>V)
            {
                printf("No\n");
                break;
            }
            else
                V=V-s[i].a;
        }
        if(i==N)
            printf("Yes\n");
        }
    return 0;
}
</span>

杭电 3177 Crixalis's Equipment

时间: 2024-10-07 00:25:35

杭电 3177 Crixalis's Equipment的相关文章

Hdu 3177 Crixalis&#39;s Equipment

Crixalis's Equipment Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 2795    Accepted Submission(s): 1141 Problem Description Crixalis - Sand King used to be a giant scorpion(蝎子) in the deserts

hdu 3177 Crixalis&#39;s Equipment(贪心)

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

hdoj 3177 Crixalis&#39;s Equipment 【贪心】

Crixalis's Equipment Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 3073    Accepted Submission(s): 1250 Problem Description Crixalis - Sand King used to be a giant scorpion(蝎子) in the deserts

HDUJ 3177 Crixalis&#39;s Equipment 贪心

Crixalis's Equipment Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 2568    Accepted Submission(s): 1059 Problem Description Crixalis - Sand King used to be a giant scorpion(蝎子) in the deserts

[HDU] 3177.Crixalis&#39;s Equipment (贪心)

Problem Description 题目大意: 有V的空间以及N个物品,对于放入每个物品有Ai(放入物品后剩余空间的减少大小),Bi(放入该物品之前需要的最小剩下空间大小,如果大于当前剩余空间大小则无法放入) Input T组数据,每组数据有N+1行,每组数据第一行输入V,N,之后的N行每行描述一个物品的Ai,Bi 0<T<= 10, 0<V<10000, 0<N<1000, 0 <Ai< V, Ai <= Bi < 1000. Output

hdu 3177 Crixalis&amp;#39;s Equipment

Crixalis's Equipment Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 2562    Accepted Submission(s): 1056 Problem Description Crixalis - Sand King used to be a giant scorpion(蝎子) in the deserts

杭电 HDU 1164 Eddy&#39;s research I

Eddy's research I Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 7117    Accepted Submission(s): 4268 Problem Description Eddy's interest is very extensive, recently  he is interested in prime

hdu 1016 Prime Ring Problem DFS解法 纪念我在杭电的第一百题

Prime Ring Problem Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 29577    Accepted Submission(s): 13188 Problem Description A ring is compose of n circles as shown in diagram. Put natural num

杭电ACM分类

杭电ACM分类: 1001 整数求和 水题1002 C语言实验题——两个数比较 水题1003 1.2.3.4.5... 简单题1004 渊子赛马 排序+贪心的方法归并1005 Hero In Maze 广度搜索1006 Redraiment猜想 数论:容斥定理1007 童年生活二三事 递推题1008 University 简单hash1009 目标柏林 简单模拟题1010 Rails 模拟题(堆栈)1011 Box of Bricks 简单题1012 IMMEDIATE DECODABILITY