UVA 11039 Building Designing greedy

Source: Internet
Author: User

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

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.