LA 3401彩色立方体【暴力】
本题是一道比较简单的模拟题。
其难度在于代码实现上面比较复杂
我们要求立方体旋转以后涂色最少的面
那么我们枚举立方体的每一种状态。然后计算每个面出现次数最多的颜色。
这样我们就可以知道多少个面需要涂。
主要难度在于枚举每一种状态的时候需要细心
//立方体
#include <bits/stdc++.h>
#define cl(a) memset(a,0,sizeof(a))
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define per(i,a,b) for(int i=b;i>=a;i--)
#define sc(x) scanf("%d",&x)
using namespace std;
const int maxn=1e5+50;
const int mod=1e9+7;
const int inf=0x3f3f3f3f;
typedef long long ll;
typedef pair<int,int> PII;
ll fpow(ll n,ll k,ll p=mod){ll r=1;for(;k;k>>=1){if(k&1)r = r*n%p;n=n*n%p;}return r;}
ll inv(ll n,ll p=mod) {return fpow(n,p-2,p);}
ll fact[maxn];
void init(){fact[0]=1;rep(i,1,maxn-1) fact[i]=fact[i-1]*i%mod;}
ll C(ll a, ll b){ll ans = fact[a]; ans =ans*inv(fact[b])%mod; ans=ans*inv(fact[a-b])%mod;return ans;}
int dist[24][6]= {{0,1,2,3,4,5},{0,2,4,1,3,5},{0,4,3,2,1,5},{0,3,1,4,2,5},{1,5,2,3,0,4},
{1,2,0,5,3,4},{1,0,3,2,5,4},{1,3,5,0,2,4},{2,1,5,0,4,3},{2,5,4,1,0,3},{2,4,0,5,1,3},{2,0,1,4,5,3},
{3,1,0,5,4,2},{3,0,4,1,5,2},{3,4,5,0,1,2},{3,5,1,4,0,2},{4,2,5,0,3,1},{4,0,2,3,5,1},{4,3,0,5,2,1},
{4,5,3,2,0,1},{5,2,1,4,3,0},{5,4,2,3,1,0},{5,3,4,1,2,0},{5,1,3,2,4,0}
};
string col[5][10];
int n;
int ans;
string change[5][10];
map<string,int>mp;
int cnt[100];
void dfs(int k)
{
if(k==n)
{
cl(cnt);
int tmp=0;
int tans=0;
//rep(i,0,n-1) {rep(j,0,5) cout<<change[i][j]<<" ";cout<<endl;}
rep(j,0,5) {cl(cnt);tmp = 0;rep(i,0,n-1){ tmp = max(tmp,++cnt[mp[change[i][j]]]);} tans += n-tmp;}
ans =min(ans,tans);
return;
}
rep(i,0,23) {rep(p,0,5) change[k][p] = col[k][dist[i][p]]; dfs(k+1);}
return;
}
int main()
{
while(cin>>n&&n)
{
mp.clear();
cl(cnt);
ans = inf;
int idx=0;
rep(i,0,n-1) rep(j,0,5) {cin>>col[i][j];if(!mp.count(col[i][j]))mp[col[i][j]]=idx++;}
rep(i,0,5) change[0][i]=col[0][i];
dfs(1);
cout<<ans<<endl;
}
return 0;
}