这题稍微有点难度了,好好写一下
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 two-dimensional. A building is specified by an ordered triple (Li, Hi, Ri) where Li and Ri are left and right coordinates, respectively, of building i and Hi is 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)
就是要弄清如何转换的?#include <iostream>
#include <algorithm>
//使用max函数需要包含algorithm头文件
using namespace std;
const int N = 1e5;
//用v来存放高度
//R表示建筑群最右边的点
int l, h, r, v[N], R;
//vector<int> skyline; 其实没有必要用一个vector来依次添加需要输出的元素,而逐次输出符合条件的元素即可,但是如果需要最后的skyline可以定义使用vector
int main() {
R = 0;
memset(v, 0, sizeof(v)); //将已开辟内存空间v的首n个字节的值设为值c
while (cin>>l>>h>>r) {
for (int i = l; i < r; i++)
v[i] = max(v[i], h);
R = max(r, R);
}
//下面也可以采用unique,就是统计不重复的个数
for (int i = 1; i < R; i++) {
if (v[i] != v[i - 1]) cout<<i<<" "<<v[i];
}
cout << R <<" "<< 0 << endl;
return 0;
}
如果建筑不仅仅包括矩形,还包括等腰三角形怎么处理