给你一些高楼大厦的坐标让你求出它们的地平线,数据量较小,用数组直接存下每个点的高度即可。线段树的解法表示还不会。
#include <stdio.h>
#include <string.h>
#define N 10005
int a[N];
int main()
{
//freopen("in", "r", stdin);
int n = 0;
int left, height, right, rightMost = 0;
while(~scanf("%d %d %d", &left, &height, &right))
{
for(int i = left; i < right; i++)
{
if(height > a[i]) a[i] = height;
}
if(right > rightMost) rightMost = right;
}
bool mk = 0;
for(int i = 1; i < rightMost; i++)
{
if(a[i] != a[i - 1]) printf("%d %d ", i, a[i]);
}
printf("%d %d\n", rightMost, 0);
return 0;
}