Introduction
Write a program which reads n dices constructed in the same way as Graph shows, and determines whether they are all different.
Input
In the first line, the number of dices n is given. In the following n lines, six integers assigned to the dice faces are given in ascending order of their corresponding labels.
Output
Print “Yes” if given dices are all different, otherwise “No” in a line.
Constraints
- 2 ≤ n ≤ 100
- 0 ≤ the integer assigned to a face ≤ 100
Samples
Sample Input 1
3
1 2 3 4 5 6
6 2 4 3 5 1
6 5 4 3 2 1
Sample Output 1
No
Sample Input 2
3
1 2 3 4 5 6
6 5 4 3 2 1
5 4 3 2 1 6
Sample Output 2
Yes
Answer
# include<bits/stdc++.h>
using namespace std;
struct dice
{ int f[7],f0[7];
void r(int a,int b,int c,int d){
int t;
t = f[a];
f[a] = f[d];
f[d] = f[c];
f[c] = f[b];
f[b] = t;
}
void roll(char cmd){
switch (cmd){
case 'S': r(1,2,6,5); break;
case 'N': r(1,5,6,2); break;
case 'W': r(1,4,6,3); break;
case 'E': r(1,3,6,4); break;
case 'R': r(2,3,5,4); break;
}
}
void MvTop(int n){
switch (n){
case 2: roll('N'); break;
case 3: roll('E'); break;
case 4: roll('W'); break;
case 5: roll('S'); break;
case 6: roll('N'); roll('N'); break;
default: break;
}
}
void copy(){
for(int i=1;i<=6;i++)
f0[i] = f[i];
}
void back(){
for(int i=1;i<=6;i++)
f[i] = f0[i];
}
bool e(dice d){
for(int i=1;i<=6;i++)
if(f[i]!=d.f[i]) return 0;
return 1;
}
bool equal(dice d){
copy();
for(int i=1;i<=6;i++){
MvTop(i);
for(int j=1;j<=4;j++){
roll('R');
if(e(d)) return 1;
}
back();
}
return 0;
}
} d[101];
bool AllDiff(int a,int n){
if(a==n) return 1;
for(int i=a+1;i<=n;i++)
if( d[a].equal(d[i]) )
return 0;
return AllDiff(a+1,n);
}
int main(){
int n;
cin>>n;
for(int k=1;k<=n;k++)
for(int i=1;i<=6;i++)
cin>>d[k].f[i];
cout<<(AllDiff(1,n) ? "Yes\n":"No\n");
return 0;
}
来源:CSDN
作者:Gin&Rum
链接:https://blog.csdn.net/weixin_45686776/article/details/103465078