블로그는 귀차니즘

First Sensation
  • 공지
  • 지역로그
  • 태그
  • 방명록

The Skyline Problem

Algorithm 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.  
    3. short Skyline[ 10001 ] = { 0, };
    4.  
    5. void InsertHeight( int Left, int Right, int Height )
    6. {
    7.     for( int i = Left; i < Right; ++i ) {
    8.         if( Skyline[ i ] < Height )
    9.             Skyline[ i ] = Height;
    10.     }
    11. }
    12.  
    13. void PrintHeight()
    14. {
    15.     int LastHeight = 0;
    16.     int CurrentHeight;
    17.     bool IsFirst = true;
    18.  
    19.     for( int i = 0; i < 10001; ++i ) {
    20.  
    21.         CurrentHeight = Skyline[ i ];
    22.  
    23.         if( CurrentHeight != LastHeight ) {
    24.  
    25.             if( IsFirst )
    26.                 IsFirst = false;
    27.             else {
    28.                 std::cout << " ";
    29.             }
    30.  
    31.             std::cout << i << " " << CurrentHeight;
    32.  
    33.             LastHeight = CurrentHeight;
    34.         }
    35.     }
    36.  
    37.     std::cout << std::endl;
    38. }
    39.  
    40. int main( int argc, char **argv )
    41. {
    42.     int Left, Height, Right;
    43.  
    44.     while( std::cin >> Left >> Height >> Right ) {
    45.         InsertHeight( Left, Right, Height );
    46.     }
    47.  
    48.     PrintHeight();
    49.  
    50.     return 0;
    51. }
    52.  



크리에이티브 커먼즈 라이센스
Creative Commons License
이 저작물은 크리에이티브 커먼즈 코리아 저작자표시-비영리-동일조건변경허락 2.0 대한민국 라이센스에 따라 이용하실 수 있습니다.

"Algorithm" 분류의 다른 글

Algorithm Traning Book - 다섯번째 문제 (0)2008/06/15
Algorithm Traning Book - 세 번째 문제 (0)2008/06/10
Algorithm Traning Book - 두 번째 문제 (0)2008/06/09
3n+1 Problem (0)2008/02/17
The Blocks Problem (0)2008/02/17
2008/02/17 08:30 2008/02/17 08:30
TAG ACM, ACM-ICPC, Array, C++, ICPC
받은 트랙백이 없고, 댓글 2개가 달렸습니다.

트랙백 주소 :: http://www.filewiki.net/tc/trackback/7

댓글을 달아 주세요

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

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

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

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

LCD Display

Algorithm 2008/02/17 08:30 귀차니스트
  1. 문제링크 : http://icpcres.ecs.baylor.edu/onlinejudge/index.php?option=com_onlinejudge&Itemid=8&category=9&page=show_problem&problem=647
  2.  의   견   : 배열을 이용 참조하여 문자열을 출력하는 식으로 구현해봤습니다. 문제는 Commit 시 공백의 문제점 때문에 Wrong Answer가 뜨더군요. 하지만, 외관상 문자열 출력형식은 같기에 굳이 Accept까지 진행하지는 않았습니다. 가로와 세로의 출력을 분리하여 구현한다면 쉬운 문제일 것입니다.
  3. 소스
    706.cpp (Language : cpp)
    1. #include <iostream>
    2. #include <string>
    3.  
    4. std::string NumberList;
    5.  
    6. unsigned char CharacterTable[ 10 ][ 5 ][ 3 ] = { { { ' ', '-', ' ' }, { '|', ' ', '|' }, { ' ', ' ', ' ' }, { '|', ' ', '|' }, { ' ', '-', ' ' } }, // 0
    7. { { ' ', ' ', ' ' }, { ' ', ' ', '|' }, { ' ', ' ', ' ' }, { ' ', ' ', '|' }, { ' ', ' ', ' ' } }, // 1
    8. { { ' ', '-', ' ' }, { ' ', ' ', '|' }, { ' ', '-', ' ' }, { '|', ' ', ' ' }, { ' ', '-', ' ' } }, // 2
    9. { { ' ', '-', ' ' }, { ' ', ' ', '|' }, { ' ', '-', ' ' }, { ' ', ' ', '|' }, { ' ', '-', ' ' } }, // 3
    10. { { ' ', ' ', ' ' }, { '|', ' ', '|' }, { ' ', '-', ' ' }, { ' ', ' ', '|' }, { ' ', ' ', ' ' } }, // 4
    11. { { ' ', '-', ' ' }, { '|', ' ', ' ' }, { ' ', '-', ' ' }, { ' ', ' ', '|' }, { ' ', '-', ' ' } }, // 5
    12. { { ' ', '-', ' ' }, { '|', ' ', ' ' }, { ' ', '-', ' ' }, { '|', ' ', '|' }, { ' ', '-', ' ' } }, // 6
    13. { { ' ', '-', ' ' }, { ' ', ' ', '|' }, { ' ', ' ', ' ' }, { ' ', ' ', '|' }, { ' ', ' ', ' ' } }, // 7
    14. { { ' ', '-', ' ' }, { '|', ' ', '|' }, { ' ', '-', ' ' }, { '|', ' ', '|' }, { ' ', '-', ' ' } }, // 8
    15. { { ' ', '-', ' ' }, { '|', ' ', '|' }, { ' ', '-', ' ' }, { ' ', ' ', '|' }, { ' ', '-', ' ' } } }; // 9
    16.  
    17. void HorizonalPrint( int Width, int Seq )
    18. {
    19.     bool IsFirst = true;
    20.     char PrintChar;
    21.     size_t VectorCount = NumberList.length();
    22.  
    23.     for( unsigned int i = 0; i < VectorCount; ++i ) {
    24.  
    25.         PrintChar = CharacterTable[ NumberList[ i ] - '0' ][ Seq ][ 1 ];
    26.  
    27.         if( i != 0 )
    28.             std::cout << " ";
    29.  
    30.         std::cout << " ";
    31.         for( int j = 0; j < Width; ++j ) {
    32.             std::cout << PrintChar;
    33.         }
    34.         std::cout << " ";
    35.     }
    36. }
    37.  
    38. void VerticalPrint( int Width, int Seq )
    39. {
    40.     bool IsFirst = true;
    41.     size_t VectorCount = NumberList.length();
    42.  
    43.     std::string PrintStr = "";
    44.  
    45.     for( unsigned int i = 0; i < VectorCount; ++i ) {
    46.  
    47.         if( i != 0 )
    48.             PrintStr += " ";
    49.  
    50.         PrintStr += CharacterTable[ NumberList[ i ] - '0' ][ Seq ][ 0 ];
    51.         for( int j = 0; j < Width; ++j ) {
    52.             PrintStr += " ";
    53.         }
    54.         PrintStr += CharacterTable[ NumberList[ i ] - '0' ][ Seq ][ 2 ];
    55.     }
    56.  
    57.     for( int Cnt = 0; Cnt < Width; ++Cnt )
    58.         std::cout << PrintStr.c_str() << std::endl;
    59. }
    60.  
    61. void PrintNumber( int Width )
    62. {
    63.     for( int i = 0; i < 5; ++i ) {
    64.  
    65.         if( i & 1 )
    66.             VerticalPrint( Width, i );
    67.         else {
    68.             HorizonalPrint( Width, i );
    69.             std::cout << std::endl;
    70.         }
    71.     }
    72. }
    73.  
    74. int main( int argc, char **argv )
    75. {
    76.     int CharacterWidth;
    77.  
    78.     while( true ) {
    79.  
    80.         std::cin >> CharacterWidth >> NumberList;
    81.  
    82.         if( CharacterWidth == 0 ) {
    83.  
    84.             if( NumberList == "0" )
    85.                 break;
    86.             else
    87.                 continue;
    88.         }
    89.  
    90.         PrintNumber( CharacterWidth );
    91.     }
    92.  
    93.     return 0;
    94. }
    95.  
    96.  

크리에이티브 커먼즈 라이센스
Creative Commons License
이 저작물은 크리에이티브 커먼즈 코리아 저작자표시-비영리-동일조건변경허락 2.0 대한민국 라이센스에 따라 이용하실 수 있습니다.

"Algorithm" 분류의 다른 글

Algorithm Traning Book - 다섯번째 문제 (0)2008/06/15
Algorithm Traning Book - 세 번째 문제 (0)2008/06/10
Algorithm Traning Book - 두 번째 문제 (0)2008/06/09
3n+1 Problem (0)2008/02/17
The Blocks Problem (0)2008/02/17
2008/02/17 08:30 2008/02/17 08:30
TAG ACM, ACM-ICPC, Array, C++, ICPC
받은 트랙백이 없고, 댓글이 없습니다.

트랙백 주소 :: http://www.filewiki.net/tc/trackback/9

댓글을 달아 주세요

◀ 이전페이지 1 다음페이지 ▶

블로그 이미지
First Sensation 귀차니스트
rss
  • 관리자
  • 글쓰기

카테고리

  • 전체 (110)
    • Computer (3)
    • Language (14)
    • Reverse Engineering (1)
    • Algorithm (9)
    • TopCoder (3)
    • Library (2)
    • Programming (19)
    • Programming Tip (9)
    • PSP-Programming (10)
    • Program (5)
    • Small Talk (31)
    • Document (4)

최근에 올라온 글

  • Gradient 작성중에 있습.... (3)
  • 게임&인터랙티브 애플리....
  • 한게임 자동테트리스 Ve.... (24)
  • Intel 64 And IA32 Arch.... (2)
  • 한게임 자동테트리스 Ve.... (24)

최근에 달린 댓글

  • 다운어덯게 받아요. difl 2008
  • 멋있네요 ㅎㅎ. 준호씨 2008
  • ^^; 그러셨군요.. 사실 동영.... 귀차니스트 2008
  • ㅋㅋ 속도 튜닝의 무서움 ㅜ.... 귀차니스트 2008
  • 관리자만 볼 수 있는 댓글입.... 비밀방문자 2008

달력

«   2009/01   »
일 월 화 수 목 금 토
        1 2 3
4 5 6 7 8 9 10
11 12 13 14 15 16 17
18 19 20 21 22 23 24
25 26 27 28 29 30 31

링크

  • kkamagui 프로그래밍 세상.
  • 류광의 번역 이야기.
  • 서광열의 프로그래밍 언....
  • 준호씨의 블로그.
  • 최익필의 이름없는 블로그.
  • 위키는 귀차니즘.

최근에 받은 트랙백

  • 궁극의 예외처리. 이름없는 블로그 2008
  • Maximum sum. 티스토리 지점 2008

글 보관함

  • 2008/12 (1)
  • 2008/11 (4)
  • 2008/10 (2)
  • 2008/09 (3)
  • 2008/08 (5)

태그목록

  • ATL
  • 플러그인
  • ASM
  • 뻘글
  • Timer
  • OpenMP
  • 상속
  • Compiler
  • Dialog
  • Code
  • 파일입출력
  • iterator_traits
  • smart Pointer
  • Gradient
  • \r\n
  • 재귀적합성
  • 전위연산
  • Inheritance
  • 파이널 데이터
  • Reflection
  • RLE
  • 병렬
  • Reverse Engineering
  • 알고리즘 트레이닝
  • ACM-ICPC
  • tr1
  • TShell
  • 파티션
  • Call By Reference
  • Generics

지역로그 : 태그 : 방명록 : 관리자 : 글쓰기
귀차니스트’s Blog is powered by Textcube 1.7.5 : Risoluto / Designed by DesignNia.net