UVA105 The Skyline Problem【水题】

With the advent of high speed graphics workstations, CAD (computer-aided design) and other areas (CAM, VLSI design) have made increasingly effective use of computers. One of the problems with drawing images is the elimination of hidden lines — lines obscured by other parts of a drawing.

  You are to design a program to assist an architect in drawing the skyline of a city given the locations of the buildings in the city. To make the problem tractable, all buildings are rectangular in shape and they share a common bottom (the city they are built in is very flat). The city is also viewed as twodimensional. A building is specified by an ordered triple (Li, Hi, Ri) where Li and Ri are the left and right coordinates, respectively, of building i (0 < Li < Ri) and Hiis the height of the building. In the diagram below buildings are shown on the left with triples

(1, 11, 5),(2, 6, 7),(3, 13, 9),(12, 7, 16),(14, 3, 25),(19, 18, 22),(23, 13, 29),(24, 4, 28)

the skyline, shown on the right, is represented by the sequence:

(1, 11, 3, 13, 9, 0, 12, 7, 16, 3, 19, 18, 22, 3, 23, 13, 29, 0)


Input

The input is a sequence of building triples. All coordinates of buildings are integers less than 10,000 and there will be at least one and at most 5,000 buildings in the input file. Each building triple is on a line by itself in the input file. All integers in a triple are separated by one or more spaces. The triples will be sorted by Li, the left x-coordinate of the building, so the building with the smallest left x-coordinate is first in the input file.

Output

The output should consist of the vector that describes the skyline as shown in the example above. In the skyline vector (v1, v2, v3, . . . , vn−2, vn−1, vn), the vi such that i is an even number represent a horizontal line (height). The vi such that i is an odd number represent a vertical line (x-coordinate). The skyline vector should represent the “path” taken, for example, by a bug starting at the minimum x-coordinate and traveling horizontally and vertically over all the lines that define the skyline. Thus the last entry in all skyline vectors will be a ‘0’.

Sample Input

1 11 5

2 6 7

3 13 9

12 7 16

14 3 25

19 18 22

23 13 29

24 4 28

Sample Output

1 11 3 13 9 0 12 7 16 3 19 18 22 3 23 13 29 0


问题链接UVA105 The Skyline Problem

问题简述:(略)

问题分析

  CAD中计算轮廓是常有的事情。

  每个建筑物有起点、终点和高度。首先需要将区间的高度叠加到一起,然后找出高度的变化即可。叠加的时候,自然是取最大值。

程序说明:(略)

题记:(略)

参考链接:(略)


AC的C++语言程序如下:

/* UVA105 The Skyline Problem */

#include <bits/stdc++.h>

using namespace std;

const int N = 10000;
int hi[N + 2];

int main()
{
    int l, h, r;

    memset(hi, 0, sizeof(hi));
    while(scanf("%d%d%d", &l, &h, &r) != EOF) {
        for(int i = l; i < r; i++)
            hi[i] = max(hi[i], h);
    }

    for(int i = 1; i <= N; i++)
        if(hi[i] != hi[i - 1]) {
            if(i != 1)
                putchar(' ');
            printf("%d %d", i, hi[i]);
        }
    putchar('\n');

    return 0;
}







  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值