UVa the Skyline Problem (Idea question)

Source: Internet
Author: User

105-the Skyline Problem

Time limit:3.000 seconds

Http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=24&page=show_problem &problem=41

This problem has a very clever idea: discretization.

What does that mean? Since the high and the left and right edges of each building are integers, you may wish to use the whole point of the line. Since the end is only a contour, then for each horizontal axis, record ordinate (height) the largest point. Finally, scan from left to right and output when altitude changes.

Complete code:

/*0.039s*/
    
#include <bits/stdc++.h>  
using namespace std;  
const int MAXN = 10005;  
    
int HI[MAXN];  
    
int main ()  
{  
    int i, L, H, r, MaxR = 0;  
    while (~SCANF ("%d%d%d", &l, &h, &r))  
    {for  
        (i = l < R; i++)  
            hi[i] = max (hi[i), h);///note right side Point does not record height  
        maxr = max (MAXR, R);  
    }  
    for (i = 1; i < MAXR ++i)  
        if (Hi[i]!= hi[i-1])  
            printf ("%d%d", I, Hi[i));  
    printf ("%d 0\n", MAXR);  
    return 0;  
}

This article URL address: http://www.bianceng.cn/Programming/sjjg/201410/45438.htm

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.