USACO section1.2 Transformations 方块转换

题目:http://www.wzoi.org/usaco/13%5C408.asp

View Code
/*
ID: qiufeih1
PROG: transform
LANG: C++
*/


#include <set>
#include <map>
#include <list>
#include <cmath>
#include <ctime>
#include <deque>
#include <queue>
#include <stack>
#include <cstdio>
#include <string>
#include <vector>
#include <cctype>
#include <cstring>
#include <sstream>
#include <fstream>
#include <cstdlib>
#include <cassert>
#include <iostream>
#include <algorithm>

using namespace std;
//Constant Declaration
/*
--------------------------*/
//#define LL long long
#define LL __int64
const int M=22;
const int INF=1<<30;
const double EPS = 1e-11;
const double PI = acos(-1.0);
/*--------------------------*/
// some essential funtion
/*
----------------------------------*/
void Swap(int &a,int &b){ int t=a;a=b;b=t; }
int Max(int a,int b){ return a>b?a:b; }
int Min(int a,int b){ return a<b?a:b; }
int Gcd(int a,int b){ while(b){b ^= a ^=b ^= a %= b;} return a; }
/*----------------------------------*/
//for (i = 0; i < n; i++)
/*
----------------------------------*/
int n;
int a[M][M], b[M][M], a1[M][M];
int l1, l2;

bool _90(int a1[][M])
{
int i, j;
for (j = 1; j <= n; j++)
{
for (i = n; i >= 1; i--)
{
if (a1[i][j] != b[j][n-i+1])
{
return 0;
}
}
}
return 1;
}


bool _180(int a1[][M])
{
int i, j;
for (i = n; i >= 1; i--)
{
for (j = n; j >= 1; j--)
{
if (a1[i][j] != b[n-i+1][n-j+1])
{
return 0;
}
}
}
return 1;
}


bool _270(int a1[][M])
{
int i, j;
for (j = n; j >= 1; j--)
{
for (i = 1; i <= n; i++)
{
if (a1[i][j] != b[n-j+1][i])
{
return 0;
}
}
}
return 1;
}


bool fs(int a1[][M])
{
int i, j;
for (i = 1; i <= n; i++)
{
for (j = 1; j <= n; j++)
{
if (a1[i][j] != b[i][n-j+1])
{
return 0;
}
}
}
return 1;
}


bool _5(int a1[][M])
{
int i, j;
for (i = 1; i <= n; i++)
{
for (j = 1; j <= n/2; j++)
{
swap(a[i][j], a[i][n-j+1]);
}
}
if (_90(a1) || _270(a1) || _180(a1))
{
return 1;
}
return 0;
}

bool _6(int a1[][M])
{
int i, j;
for (i = 1; i <= n; i++)
{
for (j = 1; j <= n; j++)
{
if (a1[i][j] != b[i][j])
{
return 0;
}
}
}
return 1;
}

int main()
{
FILE *fin = fopen ("transform.in", "r");
FILE *fout = fopen ("transform.out", "w");
//freopen("in.txt","r",stdin);
//freopen("out.txt","w",stdout);
//int t, case1 = 0;
//scanf("%d", &t);
//int n, m;
int i, j, k;
int count;
int flag;
char c;

fscanf(fin, "%d", &n);
for (i = 1; i <= n; i++)
{
for (j = 1; j <= n; j++)
{
fscanf(fin, " %c", &c);
if (c == '@')
{
a[i][j] = 1;
}
else
{
a[i][j] = 0;
}
}
}
for (i = 1; i <= n; i++)
{
for (j = 1; j <= n; j++)
{
fscanf(fin, " %c", &c);
if (c == '@')
{
b[i][j] = 1;
}
else
{
b[i][j] = 0;
}
}
}

//
if (_90(a))
{
fprintf(fout,"1\n");
}
else
{
if (_180(a))
{
fprintf(fout,"2\n");
}
else
{
if (_270(a))
{
fprintf(fout,"3\n");
}
else
{
if (fs(a))
{
fprintf(fout,"4\n");
}
else
{
if (_5(a))
{
fprintf(fout,"5\n");
}
else
{
if (_6(a))
{
fprintf(fout,"6\n");
}
else
{
fprintf(fout,"7\n");
}
}
}
}
}
}


return 0;
}



原文地址:https://www.cnblogs.com/qiufeihai/p/2421850.html