Java正六面体4种颜色染色方式

  1. /* 
  2.  * 1.   正六面体染色 
  3. 正六面体用4种颜色染色。 
  4. 共有多少种不同的染色样式? 
  5. 要考虑六面体可以任意旋转、翻转。 
  6.  */  
  7. import java.util.ArrayList;  
  8.   
  9.   
  10. public class 正六面体染色 {  
  11.     public static int sum = 0;  
  12.     /** 
  13.      * @param args 
  14.      */  
  15.     public static void main(String[] args) {  
  16.         // TODO Auto-generated method stub  
  17.         f();  
  18.     }  
  19.   
  20.     public static void f(){  
  21.         ArrayList<Integer> arr = new ArrayList<Integer>(4*4*4*4*4*4);  
  22.         for(int x1 = 1; x1 <= 4; x1++){  
  23.             for(int x2 = 1; x2 <= 4; x2++){  
  24.                 for(int x3 = 1; x3 <= 4; x3++){  
  25.                     for(int x4 = 1; x4 <= 4; x4++){  
  26.                         for(int x5 = 1; x5 <= 4; x5++){  
  27.                             for(int x6 = 1; x6 <= 4; x6++){  
  28.                                 arr.add(x1 * 100000 + x2 * 10000 + x3 * 1000 + x4 * 100 + x5 * 10 + x6);  
  29.                             }  
  30.                         }  
  31.                     }  
  32.                 }  
  33.             }  
  34.         }  
  35.   
  36.         for(int x1 = 1; x1 <= 4; x1++){  
  37.             for(int x2 = 1; x2 <= 4; x2++){  
  38.                 for(int x3 = 1; x3 <= 4; x3++){  
  39.                     for(int x4 = 1; x4 <= 4; x4++){  
  40.                         for(int x5 = 1; x5 <= 4; x5++){  
  41.                             for(int x6 = 1; x6 <= 4; x6++){  
  42.                                 if(arr.contains(x1 * 100000 + x2 * 10000 + x3 * 1000 + x4 * 100 + x5 * 10 + x6)){  
  43.                                     sum++;  
  44.                                     arr.remove(new Integer(x1 * 100000 + x2 * 10000 + x3 * 1000 + x4 * 100 + x5 * 10 + x6));  
  45.                                     up(x4,x1,x3,x6,x5,x2,arr);  
  46.                                     left(x5,x2,x1,x4,x6,x3,arr);  
  47.                                     rotate(x1,x5,x2,x3,x4,x6,arr);  
  48.                                 }  
  49.                             }  
  50.                         }  
  51.                     }  
  52.                 }  
  53.             }  
  54.         }  
  55.         System.out.println(sum);  
  56.     }  
  57.       
  58.     public static void up(int x1, int x2, int x3, int x4, int x5, int x6, ArrayList<Integer> arr){  
  59.         if(arr.remove(new Integer(x1 * 100000 + x2 * 10000 + x3 * 1000 + x4 * 100 + x5 * 10 + x6))){  
  60.                 up(x4,x1,x3,x6,x5,x2,arr);  
  61.                 left(x5,x2,x1,x4,x6,x3,arr);  
  62.                 rotate(x1,x5,x2,x3,x4,x6,arr);  
  63.         }else  
  64.             return;   
  65.     }  
  66.       
  67.     public static void left(int x1, int x2, int x3, int x4, int x5, int x6, ArrayList<Integer> arr){  
  68.         if(arr.remove(new Integer(x1 * 100000 + x2 * 10000 + x3 * 1000 + x4 * 100 + x5 * 10 + x6))){  
  69.                 up(x4,x1,x3,x6,x5,x2,arr);  
  70.                 left(x5,x2,x1,x4,x6,x3,arr);  
  71.                 rotate(x1,x5,x2,x3,x4,x6,arr);  
  72.         }else  
  73.                 return;   
  74.     }  
  75.   
  76.     public static void rotate(int x1, int x2, int x3, int x4, int x5, int x6, ArrayList<Integer> arr){  
  77.         if(arr.remove(new Integer(x1 * 100000 + x2 * 10000 + x3 * 1000 + x4 * 100 + x5 * 10 + x6))){  
  78.                 up(x4,x1,x3,x6,x5,x2,arr);  
  79.                 left(x5,x2,x1,x4,x6,x3,arr);  
  80.                 rotate(x1,x5,x2,x3,x4,x6,arr);  
  81.         }else  
  82.                 return;   
  83.     }  

猜你喜欢

转载自blog.csdn.net/qq_38500224/article/details/78773525
今日推荐