Nanyang 236--impatient C small plus

Source: Internet
Author: User

Impatient C small plus time limit:MS | Memory limit:65535 KB Difficulty:4
Describe

C Small plus some sticks, their length and quality have already known, need a machine to handle these sticks, the machine will need to use a unit of time when opening, if the weight and length of the i+1 stick is equal to the first I handle the stick, then it will not be time consuming, otherwise it would take a unit of time. Because anxious to go to date, C small plus want in the shortest time to finish the stick, can you tell him how to do?

Input
The first line is an integer t (1<t<1500), which indicates that the input data has a total T group.
The first line of each set of test data is an integer n (1<=n<=5000), which indicates that there are n sticks. The next line is to enter the L,w (0 < L, W <= 10000) of the n sticks respectively, separated by a space, indicating the length and quality of the stick.
Output
the shortest time to handle these sticks.
Sample input
3 5 4 9 5 2 2 1 3 5 1 4 3 2 2 1 1 2 2 3 1 3 2 2 3 1 

Sample output
2 1 3

Source
POJ Adaptation
//NOTE: If the weight and length of the i+1 stick is greater than or equal to the I-treated stick, then it will not be time consuming, otherwise it consumes a unit of time (greed);
1#include <stdio.h>2#include <algorithm>3 using namespacestd;4 5 structWood6 {7     intlength;8     intweight;9 } ;TenWood num[5050] ; One  A BOOLCMP (wood length, wood weight)//Dilworth theorem; - { -     if(Length.length = =weight.length) the     returnLength.weight <Weight.weight; -     Else -     returnLength.length <weight.length; - } +  - intMain () + { A     intm,n,i; atscanf"%d", &n); -      while(n--) -     { -scanf"%d",&m); -          for(i=0; i<m; i++) -scanf"%d%d", &num[i].length, &num[i].weight); in          -Sort (num, num+m, CMP); to          +         intTotal=0, temp, J; -          for(i=0; i<m; i++)//can be tested with the first set of data; the             if(Num[i].weight! =0) *             { $total++ ;Panax Notoginsengtemp=Num[i].weight; -             } the              for(j=i+1; j<m; J + +) +             { A                 if(Num[j].weight >=temp) the                 { +temp =Num[j].weight; -Num[j].weight =0 ;  $                 } $             } -         }  -printf"%d\n", total); the     } -     return 0 ;Wuyi}

Nanyang 236--impatient C small plus

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.