Helvetic Coding Contest 2018 A1

problem

The stardate is 1977 and the science and art of detecting Death Stars is in its infancy. Princess Heidi has received information about the stars in the nearby solar system from the Rebel spies and now, to help her identify the exact location of the Death Star, she needs to know whether this information is correct.

Two rebel spies have provided her with the maps of the solar system. Each map is an N × N grid, where each cell is either occupied by a star or empty. To see whether the information is correct, Heidi needs to know whether the two maps are of the same solar system, or if possibly one of the spies is actually an Empire double agent, feeding her false information.

Unfortunately, spies may have accidentally rotated a map by 90, 180, or 270 degrees, or flipped it along the vertical or the horizontal axis, before delivering it to Heidi. If Heidi can rotate or flip the maps so that two of them become identical, then those maps are of the same solar system. Otherwise, there are traitors in the Rebel ranks! Help Heidi find out.

Input

The first line of the input contains one number N (1 ≤ N ≤ 10) – the dimension of each map. Next N lines each contain N characters, depicting the first map: ‘X’ indicates a star, while ‘O’ indicates an empty quadrant of space. Next N lines each contain N characters, depicting the second map in the same format.

Output

The only line of output should contain the word Yes if the maps are identical, or No if it is impossible to match them by performing rotations and translations.

Examples

Copy

4
XOOO
XXOO
OOOO
XXXX
XOOO
XOOO
XOXO
XOXX

Copy

Yes

Copy

2
XX
OO
XO
OX

Copy

No

题意

给你一个图形,可以对其进行五种操作,分别为:

旋转90度

旋转180度

旋转270度

左右翻转

上下翻转

问能否得到指定图形

有一个结论,每一个操作只需做一次,做多次的结果可由五种排列组合得到

这样排列1~5即可

注意这五种操作的实现,常用

代码示例

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int debug_num=0;
#define debug cout<<"debug "<<++debug_num<<" :"

const int maxn=20;

struct node{
    char mapp[maxn][maxn];
};

node sta;
node ans;

int n;

bool check(node a)
{
    for(int i=1;i<=n;++i){
        for(int j=1;j<=n;++j){
            if(ans.mapp[i][j]!=a.mapp[i][j]) return false;
        }
    }
    return true;
}

//bool bfs(node sta)
//{
//    queue<node> q;
//    q.push(sta);
//    node now,next;
//    while(!q.empty())
//    {
//        now=q.front();
//        q.pop();
//
//    }
//}

node fun1(const node &a)
{
    node temp;
    for(int i=1;i<=n;++i){
        for(int j=1;j<=n;++j){
            temp.mapp[i][j]=a.mapp[n+1-j][i];
        }
    }
    return temp;
}

node fun2(const node &a)
{
    node temp;
    for(int i=1;i<=n;++i){
        for(int j=1;j<=n;++j){
            temp.mapp[i][j]=a.mapp[n+1-j][n+1-i];
        }
    }
    return temp;
}

node fun3(const node &a)
{
    node temp;
    for(int i=1;i<=n;++i){
        for(int j=1;j<=n;++j){
            temp.mapp[i][j]=a.mapp[j][n+1-i];
        }
    }
    return temp;
}

node fun4(const node &a)//上下翻转
{
    node temp;
    temp=a;
    for(int i=1;i<=n/2;++i){
        for(int j=1;j<=n;++j){
            swap(temp.mapp[i][j],temp.mapp[n+1-i][j]);
        }
    }
    return temp;
}

node fun5(const node &a)
{
    node temp;
    temp=a;
    for(int i=1;i<=n/2;++i){
        for(int j=1;j<=n;++j){
            swap(temp.mapp[j][i],temp.mapp[j][n+1-i]);
        }
    }
    return temp;
}

int main()
{
    //freopen("in.txt","r",stdin);
    ios::sync_with_stdio(false);
    cin>>n;
    for(int i=1;i<=n;++i){
        for(int j=1;j<=n;++j){
            cin>>sta.mapp[i][j];
        }
    }
    for(int i=1;i<=n;++i){
        for(int j=1;j<=n;++j){
            cin>>ans.mapp[i][j];
        }
    }
//    node xia=fun5(ans);
//    for(int i=1;i<=n;++i){
//        for(int j=1;j<=n;++j){
//            cout<<xia.mapp[i][j]<<" ";
//        }
//        cout<<endl;
//    }
    int flag=0;
    string s="12345";
    do{
        //cout<<s<<endl;
        node now=sta;
        if(check(now)) {
            flag=1;
            break;
        }
        for(int i=1;i<=5;++i){
            int id=s[i]-'0';//第几个操作
            if(id==1){
                now=fun1(now);
            }
            else if(id==2){
                now=fun2(now);
            }
            else if(id==3){
                now=fun3(now);
            }
            else if(id==4){
                now=fun4(now);
            }
            else{
                now=fun5(now);
            }
            if(check(now)){
                flag=1;
                break;
            }
        }
        if(flag) break;
    }while(next_permutation(s.begin(),s.end()));

    if(flag) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
    return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值