一、用数组储存该位置的最高点即可(图形的连续点离散化),注意左边界及右边界的情况;
注意:无论建筑物最左边是盖到哪里,你都得从1开始输出(输入输出都是integer,所以才能离散化);
#include <iostream>
#include <cstdio>
using namespace std; int main()
{
int skyline[] = {};
int L, H, R;
int rightest = ;
bool space = false; while( scanf("%d%d%d", &L, &H, &R) != EOF ) // initial
{
for(int i = L; i < R; i++)
if(H > skyline[i]) skyline[i] = H;
if(R > rightest) rightest = R;
} for(int i = ; i <= rightest; i++) // "i=rightest" is in order to print "i 0",
if(skyline[i-] != skyline[i]) // the last number.
{
if(space) printf(" ");
space = true;
printf("%d %d", i, skyline[i]);
}
printf("\n"); return ;
}