Posted on 2008-08-16 01:51
Hero 阅读(141)
评论(0) 编辑 收藏 引用 所属分类:
代码如诗--ACM
/*
ID: wangzha4
LANG: C++
JUDGE_ID: 65448BI
*/
//输出没看清楚WA好长时间
//属于立体旋转问题
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#include <math.h>
#define unllong unsigned long long
#define unint unsigned int
#define printline printf( "\n" )
typedef long long llong ;
const double PI = 2.0 * acos( 0.0 ) ;
const int Base=1000000000;
const int Capacity=100;
const int INF = 1000000 ;
const int size = 100010 ;
struct DICE
{
//char node[7] ;
int num ;
int val ;
};
struct DICE dice[size] ;
struct OUT
{
short num[size] ;
int len ;
};
struct OUT out[730] ;
int ct_out = 0 ;
int node[7] ;
int inn ;
void changeline( int posi, int x )
{
for( int k=1; k<=4; k++ )
{
if( x == node[posi] ) return ;
node[0] = node[1] ; node[1] = node[6] ;
node[6] = node[2] ; node[2] = node[4] ;
node[4] = node[0] ;
}
}
void changerow( int posi, int x )
{
for( int k=1; k<=4; k++ )
{
if( x == node[posi] ) return ;
node[0] = node[1] ; node[1] = node[3] ;
node[3] = node[2] ; node[2] = node[5] ;
node[5] = node[0] ;
}
}
void changetop( int posi, int x )
{
for( int k=1; k<=4; k++ )
{
if( x == node[posi] ) return ;
node[0] = node[4] ; node[4] = node[3] ;
node[3] = node[6] ; node[6] = node[5] ;
node[5] = node[0] ;
}
}
void input()
{
for( int i=1; i<=inn; i++ )
{
//printf( "i == %d\n", i ) ;
for( int k=1; k<=6; k++ ) scanf( "%d", &node[k] ) ;
while( node[1] != 1 )
{
changeline( 1, 1 ) ;
if( 1 == node[1] ) break ;
changerow ( 1, 1 ) ;
}
if( 2 == node[2] )
{
while( node[3] != 3 ) changetop( 3, 3 ) ;
}
else
{
while( node[3] != 2 ) changetop( 3, 2 ) ;
}//旋转完毕--左边node[1] = 1 ;上边node[3] = 2 || 3
dice[i].num = i ; dice[i].val = 0 ; int w = 10000000 ;
for( int k=1; k<=6; k++ )
{
dice[i].val += node[k] * w ; w = w / 10 ;
//dice[i].node[k-1] = node[k]+'0' ;
}
}
}
int cmp( const void *a, const void *b )
{
struct DICE *c = (struct DICE *)a ;
struct DICE *d = (struct DICE *)b ;
//if( 0 == strcmp( c->node, d->node ) )
if( c->val != d->val )
return c->val - d->val ;
else
return c->num - d->num ;
}
void process()
{
qsort( dice+1, inn, sizeof(dice[1]), cmp ) ;
}
int outcmp( const void *a, const void * b )
{
struct OUT *c = (struct OUT *)a ;
struct OUT *d = (struct OUT *)b ;
return c->num[0] - d->num[0] ;
}
void output()
{
int ct_out = 0 ;
for( int i=1; i<=inn; i++ )
{
if( dice[i].val != dice[i-1].val )
{
ct_out++ ;
out[ct_out].len = 0 ;
out[ct_out].num[out[ct_out].len++] = dice[i].num ;
}
else
{
out[ct_out].num[out[ct_out].len++] = dice[i].num ;
}
}
qsort( out+1, ct_out, sizeof(out[0]), outcmp ) ;
printf( "%d\n", ct_out ) ;
for( int i=1; i<=ct_out; i++ )
{
for( int k=0; k<out[i].len; k++ )
printf( "%d ", out[i].num[k] ) ;
printf( "\n" ) ;
}
}
int main()
{
//freopen( "frac1.in", "r", stdin ) ;
//freopen( "frac1.out","w",stdout ) ;
//freopen( "in.txt", "r", stdin ) ;
//freopen( "out.txt", "w", stdout ) ;
while( scanf( "%d", &inn ) != EOF )
{
input() ;
process() ;
output() ;
}
return 0 ;
}