USACO天梯--Transformations

Transformations

A square pattern of size N x N (1 <= N <= 10) black and whitesquare tiles is transformed into another square pattern. Write a programthat will recognize the minimum transformation that has been applied tothe original pattern given the following list of possible transformations:

  • #1: 90 Degree Rotation: The pattern was rotated clockwise 90 degrees.
  • #2: 180 Degree Rotation: The pattern was rotated clockwise 180 degrees.
  • #3: 270 Degree Rotation: The pattern was rotated clockwise 270 degrees.
  • #4: Reflection: The pattern was reflected horizontally (turnedinto a mirror image of itself by reflecting around a vertical line in themiddle of the image).
  • #5: Combination: The pattern was reflected horizontally and thensubjected to one of the rotations (#1-#3).
  • #6: No Change: The original pattern was not changed.
  • #7: Invalid Transformation: The new pattern was not obtained by any of the above methods.

In the case that more than one transform could have been used,choose the one with the minimum number above.

PROGRAM NAME: transform

INPUT FORMAT

Line 1:A single integer, N
Line 2..N+1:N lines of N characters (each either`@' or `-'); this is the square beforetransformation
Line N+2..2*N+1:N lines of N characters (each either`@' or `-'); this is the square after transformation

SAMPLE INPUT (file transform.in)

3
@-@
---
@@-
@-@
@--
--@

OUTPUT FORMAT

A single line containing the the number from 1 through 7 (describedabove) that categorizes the transformation required to change from the`before' representation to the `after' representation.

SAMPLE OUTPUT (file transform.out)

1

不算太难的一道题,主要来锻炼你的程序模块化。
以下是我的AC代码:
/*
ID:wang ming
PROG:transform
LANG:C++
*/
#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;

char a[11][11];
char b[11][11];
int n;
int one()
{
    for(int i=0;i<n;i++)
    {
        for(int j=0;j<n;j++)
        {
            if(a[n-j-1][i]!=b[i][j])
            return 0;
        }
    }

    return 1;
}
int two()
{
    for(int i=0;i<n;i++)
    {
        for(int j=0;j<n;j++)
        {
            if(a[n-1-i][n-1-j]!=b[i][j])
            return 0;
        }
    }
    return 1;
}
int three()
{
    for(int i=0;i<n;i++)
    {
        for(int j=0;j<n;j++)
        {
            if(a[j][n-1-i]!=b[i][j])
            return 0;
        }
    }
    return 1;
}
int four()
{
    for(int i=0;i<n;i++)
    {
        for(int j=0;j<n;j++)
        {
            if(a[i][n-1-j]!=b[i][j])
            return 0;
        }
    }
    return 1;
}
int five()
{
    char c[11][11];
    bool flag=1;
    for(int i=0;i<n;i++)
    {
        for(int j=0;j<n;j++)
        {
            c[i][j]=a[i][n-1-j];
        }
    }
    for(int i=0;i<n;i++)
    {
        for(int j=0;j<n;j++)
        {
            if(a[i][j]!=b[i][j])
            flag=0;
            a[i][j]=c[i][j];
        }
    }
    if(one()==1)
    {
        printf("5\n");
        return 1;
    }
    if(two()==1)
    {
        printf("5\n");
        return 1;

    }
    if(three()==1)
    {
        printf("5\n");
        return 1;
    }
    if(flag==1)
    {
        printf("6\n");
        return 1;
    }
    return 0;
}
int main()
{
    freopen("transform.in","r",stdin);
    freopen("transform.out","w",stdout);
    scanf("%d",&n);
    for(int i=0;i<n;i++)
    scanf("%s",&a[i]);
    for(int i=0;i<n;i++)
    scanf("%s",&b[i]);
    /*for(int i=0;i<n;i++)
    printf("%s\n",a[i]);
    for(int i=0;i<n;i++)
    printf("%s\n",b[i]);*/
    if(one())
         cout<<"1"<<endl;
    else if(two())
    printf("2\n");
    else if(three())
    printf("3\n");
    else if(four())
    printf("4\n");
    else if(five());
    else
    printf("7\n");
    return 0;
}

 
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值