将一个面映射到六个面去。
就例如题目给出的这个面是正面,那么你可以使它变成背面,上面,下面等。
然后进行合理性的判断。
类似于uva10051,uva437
uva10051代码:
#include <iostream>
using namespace std;
#include <stdio.h>
#include <cstring>
char wei[6][10] = {"front","back","left","right","top","bottom"};
int path[3010];
int dp[3010];
struct cube {
int top,bottom;
int face,pos;
void f(int a,int b,int c,int d) {
top = a;
bottom = b;
face = c;
pos = d;
}
}c[3010];
void print(int p) {
if(p == -1)
return;
else {
print(path[p]);
printf("%d %s\n",c[p].face,wei[c[p].pos]);
}
}
int main() {
int n;
int a,b,m,d,e,f;
int T = 1;
while(scanf("%d",&n) && n) {
int num = 0;
for(int i = 0; i < n; i++) {
scanf("%d %d %d %d %d %d",&a,&b,&m,&d,&e,&f);
c[num++].f(a,b,i + 1,0);
c[num++].f(b,a,i + 1,1);
c[num++].f(m,d,i + 1,2);
c[num++].f(d,m,i + 1,3);
c[num++].f(e,f,i + 1,4);
c[num++].f(f,e,i + 1,5);
}
memset(dp,0,sizeof(dp));
memset(path,-1,sizeof(path));
for(int i = 0; i < num; i++) {//i在上 j在下
for(int j = i + 1; j < num; j++) {
if(c[i].face < c[j].face && c[i].bottom == c[j].top && dp[j] < dp[i] + 1) {
dp[j] = dp[i] + 1;
path[j] = i;
}
}
}
int ans = 0, p = 0;
for(int i = 1; i < num; i++)
if(ans < dp[i]) {
ans = dp[i];
p = i;
}
printf("Case #%d\n",T++);
printf("%d\n",ans + 1);
print(p);
if(T)
printf("\n");
}
return 0;
}