2014-06-30

102-Ecological Bin Packing
















import java.util.*;
import java.lang.*;

public class Main{

 public static void main(String[] args) {
  // TODO Auto-generated method stub
  Scanner cin = new Scanner(System.in);
  while(cin.hasNext()){
   int i;   
   int[] input = new int[9];
   int[] move = new int[6];
   
   for(i=0 ; i<9 ; i++)
    input[i] = cin.nextInt();
   
   move[0] = input[3]+input[6]+input[2]+input[8]+input[1]+input[4];
   move[1] = input[3]+input[6]+input[1]+input[7]+input[2]+input[5];
   move[2] = input[5]+input[8]+input[0]+input[6]+input[1]+input[4];
   move[3] = input[5]+input[8]+input[1]+input[7]+input[0]+input[3];
   move[4] = input[4]+input[7]+input[0]+input[6]+input[2]+input[5];
   move[5] = input[4]+input[7]+input[2]+input[8]+input[0]+input[3];
   
   int index=0;
   int min=move[0];
   String bin=null;
   
   for(i=1 ; i<6 ; i++)
    if(move[i]<min){
     min=move[i];
     index=i;
    }
  
   switch(index){
   case 0:
    bin = "BCG";
    break;
   case 1:
    bin = "BGC";
    break;
   case 2:
    bin = "CBG";
    break;
   case 3:
    bin = "CGB";
    break;
   case 4:
    bin = "GBC";
    break;
   case 5:
    bin = "GCB";
    break;
   }
   
   System.out.println(bin+" "+min);
   input = null; 
   
   }
   
  }
        
  
 }

沒有留言:

張貼留言

(VM) Ubuntu enable ssh

OS版本:14.04 LTS 相關指令: sudo apt-get install openssh-server Port forwarding設定 : 以virtual box為例子,網路->進階->連接阜轉送(port forwarding) ...