标签:
Description
Input
Output
Sample Input
3 scarlet green blue yellow magenta cyan blue pink green magenta cyan lemon purple red blue yellow cyan green 2 red green blue yellow magenta cyan cyan green blue yellow magenta red 2 red green gray gray magenta cyan cyan green gray gray magenta red 2 red green blue yellow magenta cyan magenta red blue yellow cyan green 3 red green blue yellow magenta cyan cyan green blue yellow magenta red magenta red blue yellow cyan green 3 blue green green green green blue green blue blue green green green green green green green green sea-green 3 red yellow red yellow red yellow red red yellow yellow red yellow red red red red red red 4 violet violet salmon salmon salmon salmon violet salmon salmon salmon salmon violet violet violet salmon salmon violet violet violet violet violet violet salmon salmon 1 red green blue yellow magenta cyan 4 magenta pink red scarlet vermilion wine-red aquamarine blue cyan indigo sky-blue turquoise-blue blond cream chrome-yellow lemon olive yellow chrome-green emerald-green green olive vilidian sky-blue 0
Sample Output
4 2 0 0 2 3 4 4 0 16
1 //It is made by jump~ 2 #include <iostream> 3 #include <cstdlib> 4 #include <cstring> 5 #include <cstdio> 6 #include <cmath> 7 #include <algorithm> 8 #include <ctime> 9 #include <vector> 10 #include <queue> 11 #include <map> 12 #include <set> 13 #ifdef WIN32 14 #define OT "%I64d" 15 #else 16 #define OT "%lld" 17 #endif 18 using namespace std; 19 typedef long long LL; 20 const int MAXN = 70; 21 int biao[250][60]={ 22 {0,1,2,3,4,5},{0,2,4,1,3,5},{0,4,3,2,1,5},{0,3,1,4,2,5}, 23 {1,2,0,5,3,4},{1,5,2,3,0,4},{1,0,3,2,5,4},{1,3,5,0,2,4}, 24 {2,1,5,0,4,3},{2,0,1,4,5,3},{2,4,0,5,1,3},{2,5,4,1,0,3}, 25 {3,4,5,0,1,2},{3,5,1,4,0,2},{3,1,0,5,4,2},{3,0,4,1,5,2}, 26 {4,0,2,3,5,1},{4,2,5,0,3,1},{4,5,3,2,0,1},{4,3,0,5,2,1}, 27 {5,2,1,4,3,0},{5,1,3,2,4,0},{5,4,2,3,1,0},{5,3,4,1,2,0}, 28 }; 29 int n; 30 int paint[MAXN][60]; 31 int ans,ecnt; 32 int rotat[MAXN],color[MAXN][60]; 33 string ch; 34 int col_cnt[MAXN*6];//每种颜色 35 map<string,int>mp; 36 37 inline int getint() 38 { 39 int w=0,q=0; 40 char c=getchar(); 41 while((c<‘0‘ || c>‘9‘) && c!=‘-‘) c=getchar(); 42 if (c==‘-‘) q=1, c=getchar(); 43 while (c>=‘0‘ && c<=‘9‘) w=w*10+c-‘0‘, c=getchar(); 44 return q ? -w : w; 45 } 46 47 inline void dfs(int d){ 48 if(d==n){ 49 for(int i=0;i<n;i++) for(int j=0;j<6;j++) color[i][ biao[ rotat[i] ][j] ]=paint[i][j]; 50 51 int tot=0; 52 for(int j=0;j<6;j++) {//枚举每个面 53 memset(col_cnt,0,sizeof(col_cnt)); 54 int now=0; 55 for(int i=0;i<n;i++){//考虑每个立方体 56 col_cnt[ color[i][j] ]++; 57 now=max(now,col_cnt[color[i][j]]); 58 } 59 tot+=n-now; 60 } 61 ans=min(ans,tot); 62 63 return ; 64 } 65 for(int i=0;i<24;i++) rotat[d]=i,dfs(d+1); 66 } 67 68 inline void work(){ 69 while(1) { 70 n=getint(); if(n==0) break; 71 for(int i=0;i<n;i++) 72 for(int j=0;j<6;j++) { 73 cin>>ch; 74 if(mp[ch]!=0) paint[i][j]=mp[ch]; 75 else { mp[ch]=++ecnt; paint[i][j]=mp[ch]; } 76 } 77 ans=n*6;rotat[0]=0;//第一个立方体固定不动 78 dfs(1); printf("%d\n",ans); 79 } 80 } 81 82 int main() 83 { 84 work(); 85 return 0; 86 }
标签:
原文地址:http://www.cnblogs.com/ljh2000-jump/p/5753581.html