记录编号 109024 评测结果 AAAAAAA
题目名称 方块转换 最终得分 100
用户昵称 Gravatar752199526 是否通过 通过
代码语言 C++ 运行时间 0.002 s
提交时间 2014-07-07 16:08:49 内存使用 0.39 MiB
显示代码纯文本
#include<iostream>
#include<fstream>
#include<iomanip>
#include<cstdio>
#include<cmath>
#include <cstdlib>
#include<cstring>
#include<cctype>
#include<vector>
#include<queue>
#include<deque>
#include<stack>
#include<cassert>
#include<algorithm>
#include<functional>
#include<ctime>
using namespace std;
ifstream fin("transformations.in");
ofstream fout("transformations.out");
typedef unsigned long long LL;
int n,before[100][100],after[100][100];bool ok = true;
int Rotate(void);
bool Count(void);
bool Feflex(void);
bool Check(void);
int main()
{
	//Init
	fin>>n;
	for(int i=1;i<=n;i++)
	{
		char parttime;
		for(int j=1;j<=n;j++)
		{
			fin>>parttime;
			if(parttime=='@')before[i][j]=0;
			else before[i][j]=1;
		}
	}
	for(int i=1;i<=n;i++)
	{
		char parttime;
		for(int j=1;j<=n;j++)
		{
			fin>>parttime;
			if(parttime=='@')after[i][j]=0;
			else after[i][j]=1;
		}
	}
	//Operater
	if(Count()==false){fout<<7<<endl;return 0;}
	int ans=Rotate();
	if(ok==true){fout<<ans<<endl;return 0;}
	if(Feflex()==true){fout<<4<<endl;return 0;}
	if(Check()==true){fout<<6<<endl;return 0;}
	fout<<5<<endl;
	return 0;
}
bool Count(void)
{
	int bc0=0,ac0=0,bc1=0,ac1=0;
	for(int i=1;i<=n;i++)
	{
		for(int j=1;j<=n;j++)
		{
			if(before[i][j]==0)bc0++;
			else bc1++;
		}
	}
	for(int i=1;i<=n;i++)
	{
		for(int j=1;j<=n;j++)
		{
			if(after[i][j]==0)ac0++;
			else ac1++;
		}
	}
	if((bc0==ac0)&&(bc1==ac1))return true;
	return false;
}
int Rotate(void)
{
	int a[100][100];
	memcpy(a,before,sizeof(before));
	for(int k=1;k<=3;k++)
	{
		ok = true;
		for(int i=1;i<=n/2;i++)
		{
			for(int j=i;j<n-i+1;j++)
			{
				int t=a[i][j];
				a[i][j]=a[n-j+1][i];
				a[n-j+1][i]=a[n-i+1][n-j+1];
				a[n-i+1][n-j+1]=a[j][n-i+1];
				a[j][n-i+1]=t;
			}
		}
		for(int i=1;i<=n;i++)
		{
			for(int j=1;j<=n;j++)
			{
				if(a[i][j]!=after[i][j])ok=false;
			}
		}
		if(ok==true)return k;
	}
}
bool Feflex(void)
{
	for(int i=1;i<=n;i++)
	{
		for(int j=1;j<=n;j++)
		{
			if(before[i][j]!=after[i][n-j+1])return false;
		}
	}
	return true;
}
bool Check(void)
{
	for(int i=1;i<=n;i++)
	{
		for(int j=1;j<=n;j++)
		{
			if(before[i][j]!=after[i][j])return false;
		}
	}
	return true;
}