105-the Skyline Problem
Time limit:3.000 seconds
Http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=24&page=show_problem &problem=41
This problem has a very clever idea: discretization.
What does that mean? Since the high and the left and right edges of each building are integers, you may wish to use the whole point of the line. Since the end is only a contour, then for each horizontal axis, record ordinate (height) the largest point. Finally, scan from left to right and output when altitude changes.
Complete code:
/*0.039s*/
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 10005;
int HI[MAXN];
int main ()
{
int i, L, H, r, MaxR = 0;
while (~SCANF ("%d%d%d", &l, &h, &r))
{for
(i = l < R; i++)
hi[i] = max (hi[i), h);///note right side Point does not record height
maxr = max (MAXR, R);
}
for (i = 1; i < MAXR ++i)
if (Hi[i]!= hi[i-1])
printf ("%d%d", I, Hi[i));
printf ("%d 0\n", MAXR);
return 0;
}
This article URL address: http://www.bianceng.cn/Programming/sjjg/201410/45438.htm