题目网址:http://wikioi.com/problem/1387/
今天的速度挺快的。关键是之前就有考虑过这个题目,不过,思考的时候,比较实诚。直接就按照变换,一行一行来了。一圈完了之后,我还会继续考虑里面一行,= =,
我是蛇形矩阵玩多了咩。哎哟。枚举的原则就是应该秉承KISS(Keep It Stupid Simple)保持简单直接。目前依旧是枚举来的。话说,这个代码拉的好长呀。但是很好懂得。
#include <stdio.h>
#include <stdlib.h>
//同样是问题要简单化,可以找到每个点之间变化的联系,
//下标的联系,不要一行一行的变化。
void nity(char *input,char *output,int len)//(i,j)-->(j,len-i-1)
{
int i,j;
for(i=0 ; i < len ;i++)
{
for(j=0 ; j <len ; j++)
{
output[j*len + (len-i-1)] = input[i*len+j];
}
}
}
void one80(char *input,char *output,int len )
{
char *temp = (char *)malloc(sizeof(char) *len*len);
nity(input,temp,len);
nity(temp,output,len);
free(temp);
}
void two70(char *input,char *output,int len )
{
char *temp = (char *)malloc(sizeof(char) *len*len);
char *temp2 = (char *)malloc(sizeof(char) *len*len);
nity(input,temp,len);
nity(temp,temp2,len);
nity(temp2,output,len);
free(temp);
free(temp2);
}
void hor(char *input,char *output,int len)//(i,j)-->(i,len-j-1)
{
int i,j;
for(i=0 ; i < len ;i++)
{
for(j=0 ; j <len ; j++)
{
output[i*len + (len-j-1)] = input[i*len+j];
}
}
}
int check(char *input,char *output,int len)
{
int i,j;
for(i=0 ; i < len ;i++)
{
for(j=0 ; j <len ; j++)
{
if(input[i*len+j] != output[i*len+j])
{
return 0;
}
}
}
return 1;
}
int main()
{
int n;
scanf("%d",&n);
char *ori = (char *)malloc(sizeof(char) *n*n);
char *totrans = (char *)malloc(sizeof(char) *n*n);
char *temp = (char *)malloc(sizeof(char) *n*n);
char *temp2 = (char *)malloc(sizeof(char) *n*n);
int i,j;
for(i=0 ; i<n; i++)
{
scanf("%s",&ori[i*n]);
}
for(i=0 ; i<n; i++)
{
scanf("%s",&totrans[i*n]);
}
//#1
nity(ori,temp,n);
if( check(totrans,temp,n) ==1)
{
printf("1");
return 0;
}
//#2
nity(temp,temp2,n);
if( check(totrans,temp2,n) ==1)
{
printf("2");
return 0;
}
//#3
nity(temp2,temp,n);
if( check(totrans,temp,n) ==1)
{
printf("3");
return 0;
}
//#4
hor(ori,temp,n);
if( check(totrans,temp,n) ==1)
{
printf("4");
return 0;
}
//#5
hor(ori,temp2,n);
nity(temp2,temp,n);
if( check(totrans,temp,n) ==1)
{
printf("5");
return 0;
}
one80(temp2,temp,n);
if( check(totrans,temp,n) ==1)
{
printf("5");
return 0;
}
two70(temp2,temp,n);
if( check(totrans,temp,n) ==1)
{
printf("5");
return 0;
}
//#6
if(check(ori,totrans,n)==1)
{
printf("6");
return 0;
}
//#7
printf("7");
return 0;
}