SAMPLE INPUT (file transform.in)
3 @-@ --- @@- @-@ @-- --@
OUTPUT FORMAT
A single line containing the the number from 1 through 7 (described above) that categorizes the transformation required to change from the `before' representation to the `after' representation.SAMPLE OUTPUT (file transform.out)
1
/*
ID: conicoc1
LANG: C
TASK: transform
*/
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
void Rotation90(char *Pattern,int PatternSize)
{
char *temp;
int i,j;
temp=(char *)malloc(sizeof(char)*PatternSize*PatternSize+2);
strcpy(temp,Pattern);
for(i=1;i<=PatternSize;i++)
{
for(j=1;j<=PatternSize;j++)
{
Pattern[(i-1)*PatternSize+j]=temp[(PatternSize-j)*PatternSize+i];
}
}
free(temp);
}
void Reflection(char *Pattern,int PatternSize)
{
char *temp;
int i,j;
temp=(char *)malloc(sizeof(char)*PatternSize*PatternSize+2);
strcpy(temp,Pattern);
for(i=1;i<=PatternSize;i++)
{
for(j=1;j<=PatternSize;j++)
{
Pattern[(i-1)*PatternSize+j]=temp[(i-1)*PatternSize+PatternSize-j+1];
}
}
free(temp);
}
int main()
{
FILE *fin,*fout;
fin=fopen("transform.in","r");
fout=fopen("transform.out","w");
int PatternSize;
char *PatternBefore; //变化前形状
char *PatternAfter; //变化后形状
int i;
fscanf(fin,"%d\n",&PatternSize);
PatternBefore=(char *)malloc(sizeof(char)*PatternSize*PatternSize+2);
PatternAfter=(char *)malloc(sizeof(char)*PatternSize*PatternSize+2);
for(i=0;i<PatternSize;i++)
{
fscanf(fin,"%s",PatternBefore+i*PatternSize+1);
}
for(i=0;i<PatternSize;i++)
{
fscanf(fin,"%s",PatternAfter+i*PatternSize+1);
}
/*图形读入完毕*/
int RotationCount=0;
int Score; //记录分数
do
{
Rotation90(PatternBefore,PatternSize);
RotationCount++;
if(RotationCount==4)
{
Reflection(PatternBefore,PatternSize);
}
if(RotationCount==8)
{
break;
}
}while(strcmp(PatternBefore+1,PatternAfter+1)!=0);
switch(RotationCount)
{
case 1:Score=1;break;
case 2:Score=2;break;
case 3:Score=3;break;
case 4:Score=4;break;
case 5:Score=5;break;
case 6:Score=5;break;
case 7:Score=5;break;
case 8:Score=7;break;
}
fprintf(fout,"%d\n",Score);
return 0;
}
直接模拟并枚举每种方案好了,
只要注意旋转和对称过程中的转换就可以了。