Crixalis ' s equipment

Source: Internet
Author: User

Crixalis ' s equipment
Time limit:2000/1000 MS (java/others) Memory limit:32768/32768 K (java/others)
Total submission (s): 3097 Accepted Submission (s): 922

problem DescriptionCrixalis-sand King used to be a giant scorpion (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 have a volume of V units, and Crixalis have N equipment, each of them needs Ai units of space. When dragging him equipment into the hole, Crixalis finds that he needs more space to ensure everything are 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 is Bi units of space left. After it moved in, the volume of the hole would decrease by Ai. Crixalis wonders if he can move all him equipment into the new hole and he turns to your 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<=, 0<v<10000, 0<n<1000, 0 <Ai< V, Ai <= Bi < 1000.
&NBSP;
Output For each case, output "Yes" if Crixalis can move all he equipment into the new hole or else output "No".  
Sample Input
220 310 203 101 710 21 102 11

Sample Output
YesNo


Source HDU 2009-10 Programming Contest
RecommendLCY


Analysis Reference: http://www.cnblogs.com/Action-/archive/2012/07/03/2575069.html


#include <stdio.h> #include <stdlib.h>struct equipment{    int ai;    int bi;} Ep[1000];int Comp (const void *a,const void *b) {    struct equipment *c= (struct equipment *) a;//type conversion    struct Equipment *d= (struct equipment *) b;    Return (C->AI+D->BI)-(C->bi+d->ai);//cannot replace minus sign with greater than, otherwise it cannot ac}int main () {    int num=0;    int v=0,n=0;    int i=0;    The flag of whether the int flag=0;//succeeds. 1 is yes    scanf ("%d", &num);    while (num--)    {        flag=1;        scanf ("%d%d", &v,&n);        for (i=0;i<n;i++)        {            scanf ("%d%d", &ep[i].ai,&ep[i].bi);        }        Qsort (ep,n,sizeof (struct equipment), comp);        for (i=0;i<n;i++)        {            if (ep[i].bi>v)            {                flag=0;                break;            }            v-=ep[i].ai;        }        if (flag==0)            printf ("no\n");        else             printf ("yes\n");    }    return 0;}



Crixalis ' s equipment

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.