You are given 12 rods of equal length. Each of them is coloredin certain color. Your task is to determine in how many different ways one canconstruct a cube using these rods as edges. Two cubes are considered equal ifone of them could be rotated and put next to the other, so that thecorresponding edges of the two cubes are equally colored.
Input
The first line of input contains T (1≤T≤60), thenumber of test cases. Then T test cases follow. Each test case consists of oneline containing 12 integers. Each of them denotes the color of thecorresponding rod. The colors are numbers between 1 and 6.
Output
The output for one test consists of one integer on a line -the number of ways one can construct a cube with the described properties.
Sample Input | Sample Output |
3 1 2 2 2 2 2 2 2 2 2 2 2 1 1 2 2 2 2 2 2 2 2 2 2 1 1 2 2 3 3 4 4 5 5 6 6 | 1 5 312120 |
正方体的12条棱,给你12个颜色(1到6,可重复),问有多少种正方体,旋转相同算一种。
一个正方体有24种置换(以每个面为顶都有4种),所以最后答案除以24。
1.静止不动,12个循环,每个长度为1。
2.以面心旋转90,180,270。旋转90和270的时候有6个循环,每个循环节长度为4。180的时候3个循环,循环节长度为2。
3.以对立顶点为轴旋转120,240,4组对角顶点,每组有120和240度,所以8个循环,循环节长度3。
4.以对立棱的中点为轴旋转180,6组对立棱,6个循环,两个棱的循环节是1,剩下的循环节是2。
这就是正方体的全部置换情况了,其它组合情况也都和这里的情况等价。
#include<iostream>
#include<algorithm>
#include<queue>
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<cstring>
#include<set>
#include<map>
#define INF 0x3f3f3f3f
#define MAXN 2000010
#define MAXM 1500
#define MOD 1000000007
#define MAXNODE 8*MAXN
#define eps 1e-9
using namespace std;
typedef long long LL;
int T,cnt[10];
LL fac(int n){
LL ret=1;
for(int i=2;i<=n;i++) ret*=i;
return ret;
}
int main(){
freopen("in.txt","r",stdin);
scanf("%d",&T);
while(T--){
memset(cnt,0,sizeof(cnt));
int t;
for(int i=0;i<12;i++){
scanf("%d",&t);
cnt[t]++;
}
LL ans=fac(12); //不旋转
for(int i=1;i<=6;i++) ans/=fac(cnt[i]);
//绕面心旋转90,270,循环节是4
int flag=1;
for(int i=1;i<=6;i++){
if(cnt[i]%4){
flag=0;
break;
}
}
if(flag){
LL t=fac(3);
for(int i=1;i<=6;i++) t/=fac(cnt[i]/4);
ans+=3*2*t;
}
//绕面心旋转180,循环节是2
flag=1;
for(int i=1;i<=6;i++){
if(cnt[i]%2){
flag=0;
break;
}
}
if(flag){
LL t=fac(6);
for(int i=1;i<=6;i++) t/=fac(cnt[i]/2);
ans+=3*t;
}
//以对角顶点为轴旋转120,240,循环节是3
flag=1;
for(int i=1;i<=6;i++){
if(cnt[i]%3){
flag=0;
break;
}
}
if(flag){
LL t=fac(4);
for(int i=1;i<=6;i++) t/=fac(cnt[i]/3);
ans+=4*2*t;
}
//以对立的棱的中点为轴旋转180,除了那两条棱外循环节是2,两条棱循环节是1
for(int i=1;i<=6;i++) if(cnt[i]>0){
cnt[i]--;
for(int j=0;j<=6;j++) if(cnt[j]>0){
cnt[j]--;
flag=1;
for(int k=1;k<=6;k++){
if(cnt[k]%2){
flag=0;
break;
}
}
if(flag){
LL t=fac(5);
for(int k=1;k<=6;k++) t/=fac(cnt[k]/2);
ans+=6*t;
}
cnt[j]++;
}
cnt[i]++;
}
printf("%d\n",ans/24);
}
return 0;
}