Nested Dolls
Time Limit: 1000MS |
|
Memory Limit: 65536K |
Total Submissions: 7943 |
|
Accepted: 2158 |
Description
Dilworth is the world's most prominent collector of Russian nested dolls:he literally have thousands of them! You know, the wooden hollow dolls of different sizes of which the smallest doll are contained in the second smallest, and t His doll are in turn contained in the next one and so forth. One day and he wonders if there is another the nesting them so he'll end up with fewer nested dolls? After all, this would make he collection even more magnificent! He unpacks each nested doll and measures the width and height of each contained doll. A Doll with width w1 and height h1 would fit in another doll of width w2 and height h= If and only if W1 < w2 and H1 < h2. Can him calculate the smallest number of nested dolls possible to assemble from his massive list of measurements?
Input
On the first line of input was a single positive integer 1≤ t ≤20 specifying the number of test cases to follow. Each test case begins with a positive integer 1≤ m ≤20000 on a line of itself telling the number of dolls in T He test case. Next follow 2m positive integers w1, H1,w2, H2, ...,wm, hm , where wi is the width and hi are the height of doll number I. 1 ≤ wi, hi ≤10000 for all i.
Output
For all test case there should is one line of output containing the minimum number of nested dolls possible.
Sample Input
43 - - + - - +4 - - Ten Ten - - + -3Ten - - - - Ten4Ten Ten - - + - the Wuyi
Sample Output
1 2 3 2
Source
Nordic//a doll with width
W1 and height
h1 would fit in another doll of width
W2 and Height
h= if and only if
W1 <
W2 and
h1 <
h2 Is there an equal sign that affects the return value in the BOOL function;
L The same w to be in descending order, l in ascending order;
1#include <stdio.h>2#include <algorithm>3 using namespacestd;4 5 structDool6 {7 intl;8 intW;9 } ;TenDool num[20020] ; One A BOOLCMP (dool L, Dool W)//dirworth theorem: l sort in ascending order; When L is equal, W also descending, excluding the equal sign relationship; - { - if(L.L = =W.L) the returnL.W >W.W; - Else - returnL.L <W.L; - } + - intMain () + { A intm,n,i; atscanf"%d",&m); - while(m--) - { -scanf"%d",&n); - for(i=0; i<n; i++) -scanf"%d%d", &NUM[I].L, &NUM[I].W); inSort (num, num+N, CMP); - to intTemp, total=0, J; + for(i=0; i<n; i++) - { the if(NUM[I].W! =0) * { $temp=NUM[I].W;Panax Notoginsengtotal++ ; - for(j=i+1; j<n; J + +) the { + if(Num[j].w >temp) A { thetemp =NUM[J].W; +NUM[J].W =0 ; - } $ } $ } - } -printf"%d\n", total); the } - return 0;Wuyi}
Poj3636--nested Dolls