Section 1.2.3 水模拟

发现神站一枚http://www.wzoi.org/usaco/ 

usaco的翻译。

= =想到学姐之前吐槽CP让她们翻译usaco,再看看这名字= =卧槽果然是我们学校搞的。

真是羡慕中学就能搞信息学之类的同学啊(这里:考不上竞赛班的蒟蒻一枚)

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

翻译如上

大概就是各种旋转变换问是否可实现

有个简化的办法

  发现转90度 重复多次就可以搞出180 270 什么的

然后找出旋转(i, j) 会变成(j, n - i + 1) 

然后就好了

#include <bits/stdc++.h>
using namespace std;

const int N =  12;
int n;
char pre[N][N], after[N][N], temp[N][N], out[N][N];

void myrotate(){
    int i, j;
    for(i = 1; i <= n; i++){
        for(j = 1; j <= n; j++){
            out[j][n+1-i] = temp[i][j];
        }
    }
}

bool check(){
    int i, j;
    for(i = 1; i <= n; i++){
        for(j = 1; j <= n; j++){
            if(out[i][j] != after[i][j])    return false;
        }
    }
    return true;
}

void reflect(){
    int i, j;
    for(i = 1; i <= n; i++){
        for(j = 1; j <= n; j++){
            out[i][n-j+1] = pre[i][j];
        }
    }
}
int solve(){
    int i, j, k;
    for(i = 1; i <= 3; i++){
        myrotate();
        if(check()) return i;
        for(j = 1; j <= n; j++) for(k = 1; k <= n; k++)
            temp[j][k] = out[j][k];
    }
    reflect();
    if(check()) return 4;
    for(i = 1; i <= n; i++) for(j = 1; j <= n; j++) temp[i][j] = out[i][j];
    for(i = 1; i <= 3; i++){
        myrotate();
        if(check()) return 5;
        for(int j = 1; j <= n; j++) for(int k = 1; k <= n; k++)
        temp[j][k] = out[j][k];
    }

    for(i = 1; i <= n; i++) for(j = 1; j <= n; j++) out[i][j] = pre[i][j];
    if(check()) return 6;
    return 7;
}
int main()
{
    #ifndef poi
    freopen("transform.in","r",stdin);
    freopen("transform.out","w",stdout);
    #endif

    int i, j;
    scanf("%d", &n);

    for(i = 1; i <= n; i++){
        scanf("%s", pre[i] + 1);
        for(j = 1; j <= n; j++) temp[i][j] = pre[i][j];
    }
    for(i = 1;i <=n; i++){
        scanf("%s", after[i] + 1);
    }
    printf("%d
", solve());
}
View Code
原文地址:https://www.cnblogs.com/bbbbbq/p/4631497.html