Ultraviolet A Problem 105-Skyline Problem

Source: Internet
Author: User
Tags dot net
// Va problem 105-Skyline problem // verdict: accepted // submission date: 2011-11-22/Ultraviolet Run Time: 0.036 S // All Rights Reserved (c) qiu, 2011. Metaphysis # Yeah dot net // [problem solving method] // initially, we wanted to obtain all the intersection points and then determine whether the intersection points are in the rectangle, but the written Code Ugly and ugly, I thought, isn't there any better method? Taking a closer look at the figure given by the question, do we not use arrays to simulate tall buildings? Anyway, the maximum coordinate is // 10000. A one-dimensional array is used to represent the abscissa. The array value is used to represent the ordinate, so the "Parallel" of the rectangle is quite easy to represent, you only need to // determine the maximum ordinate of a horizontal coordinate. You can use the idea similar to the filling method to create an array of "high-rise buildings". For a given rectangle (L, H, H, r), set all values in the range of [L, R] as H. Of course, the precondition is that the previous value of the array is less than // H, this is equivalent to achieving a higher building to overwrite a shorter building, thus conveniently representing the "union" of the rectangle ", then it is not difficult to input/output the coordinate value as required. # Include <iostream> # include <cstring> using namespace STD; # define maxn 10010int grid [maxn]; int main (INT argc, char const * argv []) {int left, height, right, leftmost, rightmost = 0; bool leftsetted = false; memset (grid, 0, sizeof (GRID); While (CIN> left> height> right) {for (INT I = left; I <= right; I ++) grid [I] = max (grid [I], height); If (! Leftsetted) {leftmost = left; leftsetted = true;} rightmost = max (rightmost, right) ;}cout <leftmost <"" <grid [leftmost]; int current = leftmost; For (INT I = leftmost; I <= rightmost; I ++) {If (grid [I] = grid [current]) continue; else {If (grid [I]> grid [current]) cout <"<I <" "<grid [I]; elsecout <"" <(I-1) <"" <grid [I]; current = I ;}} cout <"" <rightmost <"0 \ n"; return 0 ;}

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.