Title Link: UVA-11039
Test Instructions Description: Architect Design house has two requirements: first, each floor must be larger than the size of the house above the floor; second, the building is dyed in blue and red, and each adjoining two floors cannot dye the same color. Now give the number of floors and the size of each floor (the size of the floor is not given in order), to find out the maximum number of floors to meet such requirements.
Algorithm analysis: The floor size according to the order from large to small, and then traverse the same time to record the different colors of the adjacent floor, the floor can not meet the requirements to remove.
1#include <iostream>2#include <cstdio>3#include <cstring>4#include <cstdlib>5#include <cmath>6#include <algorithm>7 #defineINF 0x7fffffff8 using namespacestd;9 Const intmaxn=500000+Ten;Ten One intN,AN[MAXN]; A - intcmpintIintj) - { theI=abs (i); j=ABS (j); - returnI>J; - } - + intMain () - { + intT;SCANF ("%d",&t); A while(t--) at { -scanf"%d",&n); - for(intI=0; i<n; i++) scanf ("%d",&an[i]); -Sort (an,an+n,cmp); - intCnt=1, flag= an[0]>0?1: -1 ; - for(intI=1;i<N;) in { - intf= an[i]>0?1: -1 ; to while(F==flag && i<N) + { -i++; thef= an[i]>0?1: -1 ; * } $ if(f! = Flag && i<N)Panax Notoginseng { -CNT + + ; theflag=F; +i + + ; A } the } +printf"%d\n", CNT); - } $ return 0; $}
UVA 11039 Building Designing greedy