-
#include <iostream>
-
#include <queue>
-
#include <string>
-
-
struct SortNode {
-
int Total;
-
std::string OutputStr;
-
};
-
-
bool operator < ( const SortNode &Left, const SortNode &Right )
-
{
-
size_t LeftLength = Left.OutputStr.length();
-
size_t RightLength = Right.OutputStr.length();
-
-
if( ( Left.Total == Right.Total ) && ( LeftLength == RightLength ) ) {
-
for( int i = 0; i < 3; i++ ) {
-
-
char LeftChar = Left.OutputStr[ i ];
-
char RightChar = Right.OutputStr[ i ];
-
-
if( LeftChar == RightChar )
-
continue;
-
else if( LeftChar > RightChar )
-
return true;
-
else
-
return false;
-
}
-
}
-
-
return ( Left.Total > Right.Total );
-
}
-
-
int main( int argc, char **argv )
-
{
-
unsigned int Bottle[ 9 ] = { 0, };
-
-
while( std::cin >> Bottle[ 0 ] >> Bottle[ 1 ] >> Bottle[ 2 ] >> Bottle[ 3 ] >> Bottle[ 4 ] >> Bottle[ 5 ] >> Bottle[ 6 ] >> Bottle[ 7 ] >> Bottle[ 8 ] ) {
-
std::priority_queue< SortNode > BackTracking;
-
-
SortNode Temp;
-
Temp.Total = 0;
-
BackTracking.push( Temp );
-
-
while( true ) {
-
-
SortNode ProcessNode = BackTracking.top();
-
BackTracking.pop();
-
-
size_t ProcessStrLength = ProcessNode.OutputStr.length();
-
-
if( ProcessStrLength == 3 ) {
-
std::cout << ProcessNode.OutputStr << " " << ProcessNode.Total << std::endl;
-
break;
-
}
-
-
ProcessStrLength *= 3;
-
-
if( ProcessNode.OutputStr.find( "C" ) == UINT_MAX ) {
-
SortNode CNode( ProcessNode );
-
-
CNode.Total += ( Bottle[ ProcessStrLength ] + Bottle[ ProcessStrLength + 1 ] );
-
CNode.OutputStr += "C";
-
-
BackTracking.push( CNode );
-
}
-
-
if( ProcessNode.OutputStr.find( "G" ) == UINT_MAX ) {
-
SortNode GNode( ProcessNode );
-
-
GNode.Total += ( Bottle[ ProcessStrLength ] + Bottle[ ProcessStrLength + 2 ] );
-
GNode.OutputStr += "G";
-
-
BackTracking.push( GNode );
-
}
-
-
if( ProcessNode.OutputStr.find( "B" ) == UINT_MAX ) {
-
SortNode BNode( ProcessNode );
-
-
BNode.Total += ( Bottle[ ProcessStrLength + 1 ] + Bottle[ ProcessStrLength + 2 ] );
-
BNode.OutputStr += "B";
-
-
BackTracking.push( BNode );
-
}
-
}
-
}
-
-
return 0;
-
}
댓글을 달아 주세요