Photolog

Through the Looking-Glass
2010-10-12: Through the Looking-Glass
My radio speaks is binary!
2010-10-10: My radio speaks is binary!
Gigaminx: (present for my birthday)
2010-09-16: Gigaminx: (present for my birthday)
Trini on bike
2010-09-05: Trini on bike
Valporquero
2010-08-28: Valporquero
My new bike!
2010-08-22: My new bike!
Mario and Ana's wedding
2010-08-13: Mario and Ana's wedding
Canyoning in Guara
2010-08-07: Canyoning in Guara
Trini and Mari in Marbella
2010-08-05: Trini and Mari in Marbella
Trini and Chelo in Tabarca
2010-08-03: Trini and Chelo in Tabarca
Valid XHTML 1.1
Log in
Back to list of problems

The Skyline Problem

105.c

#include <stdio.h>

int skyline[10020];

struct building {
	int L;
	int H;
	int R;
};

int num;
struct building bui[5010];

int
main(void) {
	int i,j;
	int last=0;
	int ini=0;

	memset(skyline, 0, sizeof(skyline));
	for(num=0; num<5010; num++) {
		if (scanf("%d %d %d", &bui[num].L, &bui[num].H, &bui[num].R) != 3) {
			break;
		}
		if (bui[num].L > 10000 || bui[num].R > 10000 || bui[num].L > bui[num].R) {
			abort();
		}
	}
	for(i=bui[0].L; i<10020; i++) {
		int max=0;
		for(j=0; j<num; j++) {
			if (bui[j].L <= i && bui[j].R > i) {
				if (bui[j].H > max) {
					max = bui[j].H;
				}
			}
		}
		if (max != last) {
			last = max;
			if (ini) {
				printf(" ");
			} else {
				ini=1;
			}
			printf("%d %d", i, last);
		}
	}
	printf("\n");
	return 0;
}