블로그는 귀차니즘

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

Ecological Bin Packing

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=38
  2.  의   견   : 나올 수 있는 경우의 수는 3! 개 입니다. 즉, 경우의 수가 적으므로 6가지 경우에 대한 측정값들을 수동으로 계산하여 출력할 수 있습니다. 하지만, 일반적으로 계산을 해보고자 하는 마음으로 priority_queue와 string을 짝으로 조합하여 구현을 했습니다.
  3. 소스
    103.cpp (Language : cpp)
    1. #include <iostream>
    2. #include <queue>
    3. #include <string>
    4.  
    5. struct SortNode {
    6.     int Total;
    7.     std::string OutputStr;
    8. };
    9.  
    10. bool operator < ( const SortNode &Left, const SortNode &Right )
    11. {
    12.     size_t LeftLength = Left.OutputStr.length();
    13.     size_t RightLength = Right.OutputStr.length();
    14.  
    15.     if( ( Left.Total == Right.Total ) && ( LeftLength == RightLength ) )    {
    16.         for( int i = 0; i < 3; i++ )    {
    17.  
    18.             char LeftChar = Left.OutputStr[ i ];
    19.             char RightChar = Right.OutputStr[ i ];
    20.  
    21.             if( LeftChar == RightChar )
    22.                 continue;
    23.             else if( LeftChar > RightChar )
    24.                 return true;
    25.             else
    26.                 return false;
    27.         }
    28.     }
    29.  
    30.     return ( Left.Total > Right.Total );
    31. }
    32.  
    33. int main( int argc, char **argv )
    34. {
    35.     unsigned int Bottle[ 9 ] = { 0, };
    36.  
    37.     while( std::cin >> Bottle[ 0 ] >> Bottle[ 1 ] >> Bottle[ 2 ] >> Bottle[ 3 ] >> Bottle[ 4 ] >> Bottle[ 5 ] >> Bottle[ 6 ] >> Bottle[ 7 ] >> Bottle[ 8 ] )    {
    38.         std::priority_queue< SortNode > BackTracking;
    39.  
    40.         SortNode Temp;
    41.         Temp.Total = 0;
    42.         BackTracking.push( Temp );
    43.  
    44.         while( true )   {
    45.  
    46.             SortNode ProcessNode = BackTracking.top();
    47.             BackTracking.pop();
    48.  
    49.             size_t ProcessStrLength = ProcessNode.OutputStr.length();
    50.  
    51.             if( ProcessStrLength == 3 ) {
    52.                 std::cout << ProcessNode.OutputStr << " " << ProcessNode.Total << std::endl;
    53.                 break;
    54.             }
    55.  
    56.             ProcessStrLength *= 3;
    57.  
    58.             if( ProcessNode.OutputStr.find( "C" ) == UINT_MAX ) {
    59.                 SortNode CNode( ProcessNode );
    60.  
    61.                 CNode.Total += ( Bottle[ ProcessStrLength ] + Bottle[ ProcessStrLength + 1 ] );
    62.                 CNode.OutputStr += "C";
    63.  
    64.                 BackTracking.push( CNode );
    65.             }
    66.  
    67.             if( ProcessNode.OutputStr.find( "G" ) == UINT_MAX ) {
    68.                 SortNode GNode( ProcessNode );
    69.  
    70.                 GNode.Total += ( Bottle[ ProcessStrLength ] + Bottle[ ProcessStrLength + 2 ] );
    71.                 GNode.OutputStr += "G";
    72.  
    73.                 BackTracking.push( GNode );
    74.             }
    75.  
    76.             if( ProcessNode.OutputStr.find( "B" ) == UINT_MAX ) {
    77.                 SortNode BNode( ProcessNode );
    78.  
    79.                 BNode.Total += ( Bottle[ ProcessStrLength + 1 ] + Bottle[ ProcessStrLength + 2 ] );
    80.                 BNode.OutputStr += "B";
    81.  
    82.                 BackTracking.push( BNode );
    83.             }
    84.         }
    85.     }
    86.  
    87.     return 0;
    88. }



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

"Algorithm" 분류의 다른 글

Dovelet - (1) (0)2010/03/13
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
2008/02/17 08:30 2008/02/17 08:30
TAG ACM, ACM-ICPC, C++, ICPC, priority_queue
받은 트랙백이 없고, 댓글이 없습니다.

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

댓글을 달아 주세요

◀ 이전페이지 1 ... 109 110 111 112 113 114 115 116 117 ... 119 다음페이지 ▶

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

카테고리

  • 전체 (119)
    • Computer (3)
    • Language (14)
    • Reverse Engineering (1)
    • Algorithm (10)
    • TopCoder (3)
    • Library (2)
    • Programming (21)
    • Programming Tip (9)
    • PSP-Programming (10)
    • Program (5)
    • Small Talk (33)
    • Document (4)
    • OS Develope (4)

최근에 올라온 글

  • Dovelet - (1).
  • Script Interpreter - b....
  • VirtualHttpServer - 가.... (2)
  • 음.. 여러가지 일이 있.... (2)
  • 어후.. 드디어 인터럽트....

최근에 달린 댓글

  • 좋은정보 감사합니다. :). 블루아사 03:05
  • 헠 ㅋ 다음에도 들러주세용 ㅋㅋ. 귀차니스트 03/09
  • ㅎㅎ RSS로 첨 온 글이네.ㅋ. 당구리 02/22
  • 음.. 한글화 파일 0.5 버젼은.... 귀차니스트 02/22
  • 관리자만 볼 수 있는 댓글입.... 비밀방문자 01/30

달력

«   2010/03   »
일 월 화 수 목 금 토
  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 프로그래밍 세상.
  • runner님의 이글루.
  • 당구리의 마굿간.
  • 동우fly.
  • 류광의 번역 이야기.
  • 서광열의 프로그래밍 언....
  • 준호씨의 블로그.
  • 최익필의 이름없는 블로그.
  • 위키는 귀차니즘.

최근에 받은 트랙백

  • 한게임 테트리스 인공지.... 고니's Life 2009
  • ACM 706 (Uva ID) : LCD.... 알고리즘 트레이닝 : Oh... 2009
  • 문제 4 : LCD 디스플레.... 최익필의 이름없는 블로그 2009
  • 궁극의 예외처리. 이름없는 블로그 2008
  • Maximum sum. 티스토리 지점 2008

글 보관함

  • 2010/03 (2)
  • 2010/02 (1)
  • 2010/01 (1)
  • 2009/12 (3)
  • 2009/08 (1)

태그목록

  • Inheritance
  • 이미지 프로세싱
  • istream_iterator
  • 관악기
  • Dynamic Programming
  • OTF
  • Array
  • 어쌔신 크리드
  • Catch
  • 플러그인
  • Decompiler
  • 병렬처리
  • Linux
  • smart Pointer
  • 멀티맵
  • istreambuf_iterator
  • As 형 변환
  • AppWizard
  • Contest
  • HTTP
  • 쉘
  • 디아블로3
  • Mine Sweeper
  • 1.35
  • 디코드
  • Kernel
  • Assassin's Creed
  • 컬러체험단
  • Sector
  • System.Xml

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