#UVa:102-Ecological Bin Packing

硬爆,把每一種組合都算過比出最小的即可。

C++(0.048)

/*******************************************************/
/* UVa 102 Ecological Bin Packing                      */
/* Author: LanyiKnight [at] knightzone.studio             */
/* Version: 2012/03/14                                 */
/*******************************************************/
#include<iostream>
#include<cstdio>
using namespace std;

int main(){
  int brown[5], green[5], clear[5];
  int move[10];
  const string answer[10] = { "BCG", "BGC",
                              "CBG", "CGB",
                              "GBC", "GCB" };
  int min_index;
  while( scanf( "%d", &brown[0] ) != EOF ){
    scanf( "%d%d%d%d%d%d%d%d", &green[0], &clear[0]
                             , &brown[1], &green[1], &clear[1]
                             , &brown[2], &green[2], &clear[2] );
    move[0] = brown[1]+brown[2]+green[0]+green[1]+clear[0]+clear[2];
    move[1] = brown[1]+brown[2]+green[0]+green[2]+clear[0]+clear[1];
    move[2] = brown[0]+brown[2]+green[0]+green[1]+clear[1]+clear[2];
    move[3] = brown[0]+brown[1]+green[0]+green[2]+clear[1]+clear[2];
    move[4] = brown[0]+brown[2]+green[1]+green[2]+clear[0]+clear[1];
    move[5] = brown[0]+brown[1]+green[1]+green[2]+clear[0]+clear[2];

    min_index = 0;
    for( int i = 1 ; i < 6 ; i++ )
      if( move[i] < move[min_index] )
        min_index = i;
    printf( "%s %d\n", answer[min_index].c_str(), move[min_index] );

  }

  return 0;
}
廣告

Comment

There is no comment on this post. Be the first one.

發表迴響

這個網站採用 Akismet 服務減少垃圾留言。進一步瞭解 Akismet 如何處理網站訪客的留言資料

%d 位部落客按了讚: