The Skyline Problem

Algorithm/Acm 2008/02/17 08:30 귀차니스트
  1. 문제링크 : http://icpcres.ecs.baylor.edu/onlinejudge/index.php?option=com_onlinejudge&Itemid=8&category=3&page=show_problem&problem=41
  2.  의   견   : 일일이 하나의 경우에 대해서 앞의 모든 경우를 검사하는 것이 아님을 가르쳐주는 문제. 방법은 배열을 선언, 입력이 들어올 때마다 배열을 범위로 선택 값을 갱신합니다. 출력시에는 다른 지점의 인덱스만 출력하면 됩니다.
  3. 소스
    105.cpp (Language : cpp)
    1. #include <iostream>
    2. short Skyline[ 10001 ] = { 0, };
    3. void InsertHeight( int Left, int Right, int Height )
    4. {
    5.     for( int i = Left; i < Right; ++i ) {
    6.         if( Skyline[ i ] < Height )
    7.             Skyline[ i ] = Height;
    8.     }
    9. }
    10. void PrintHeight()
    11. {
    12.     int LastHeight = 0;
    13.     int CurrentHeight;
    14.     bool IsFirst = true;
    15.     for( int i = 0; i < 10001; ++i ) {
    16.         CurrentHeight = Skyline[ i ];
    17.         if( CurrentHeight != LastHeight ) {
    18.             if( IsFirst )
    19.                 IsFirst = false;
    20.             else {
    21.                 std::cout << " ";
    22.             }
    23.             std::cout << i << " " << CurrentHeight;
    24.             LastHeight = CurrentHeight;
    25.         }
    26.     }
    27.     std::cout << std::endl;
    28. }
    29. int main( int argc, char **argv )
    30. {
    31.     int Left, Height, Right;
    32.     while( std::cin >> Left >> Height >> Right ) {
    33.         InsertHeight( Left, Right, Height );
    34.     }
    35.     PrintHeight();
    36.     return 0;
    37. }



크리에이티브 커먼즈 라이센스
Creative Commons License

"Algorithm / Acm" 분류의 다른 글

The Blocks Problem (0)2008/02/17
3n+1 Problem (0)2008/02/17
Ecological Bin Packing (0)2008/02/17
Maximum Sum (0)2008/02/17
LCD Display (3)2008/02/17
2008/02/17 08:30 2008/02/17 08:30

댓글을 달아 주세요

  1. alex 2008/08/19 23:39  댓글주소  수정/삭제  댓글쓰기

    그냥 using namespace std 쓰시지 ...
    큰 작업도 아니고 uva 문제 푸는 정도면
    유도리 있게 코딩하시는거도 좋다고 생각합니다.

    • 귀차니스트 2008/09/21 21:21  댓글주소  수정/삭제

      아 ㅋㅋ 물론 진짜 ACM 대회를 나가게 된다면 시간이 중요하니 그럴수 있겠지만.. 평상시 일 때는 원칙을 되도록 지키고 싶어서 그렇습니다^^.