USACO SECTION 1.2 Transformations

Transformations

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;
}
	


 

 直接模拟并枚举每种方案好了,

只要注意旋转和对称过程中的转换就可以了。

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值