UVa - 105 The Skyline Problem

#include<stdio.h>
#include<string.h>
#include<limits.h>

#define  MX 20000

long maxs[MX],iMaxs,maxZ=LLONG_MIN;
long x,y,z,lastItem=0,lastIndex;

int main() {

//    freopen("input.txt","r",stdin);
//    freopen("output.txt","w",stdout);   

    while(scanf("%ld%ld%ld",&x,&y,&z)==3){

        for(iMaxs=x;iMaxs<=z;iMaxs++){
            if(maxs[iMaxs] < y) maxs[iMaxs]=y;
        }

        if(maxZ<z) maxZ=z;
    }

    for(iMaxs=0;iMaxs<=maxZ;iMaxs++){

        if(maxs[iMaxs]!=lastItem){

            if(lastItem>maxs[iMaxs]) printf("%ld %ld",iMaxs-1,maxs[iMaxs]);
            else printf("%ld %ld",iMaxs,maxs[iMaxs]);

            lastItem=maxs[iMaxs];lastIndex=iMaxs;

            if(iMaxs!=maxZ) printf(" ");
        }
    }

    if(maxs[maxZ]!=0) printf(" %ld 0\n",lastIndex);

    return 0;
}

No comments:

Post a Comment