zoukankan      html  css  js  c++  java
  • USACO transform

      直接暴力模拟即可:

      

    /*
        ID: m1500293
        LANG: C++
        PROG: transform
    */
    #include <cstdio>
    #include <algorithm>
    #include <cstring>
    
    using namespace std;
    
    int n;
    char tps[15][15];
    char s[15][15];
    char e[15][15];
    
    bool IsSame(char a[][15], char b[][15])
    {
        bool flog = true;
        for(int i=0; i<n&&flog; i++)
            for(int j=0; j<n&&flog; j++)
                if(a[i][j] != b[i][j]) flog = false;
        return flog;
    }
    
    
    
    void debug(char a[][15])
    {
        printf("debug========================
    ");
        for(int i=0; i<n; i++)
        {
            for(int j=0; j<n; j++)
                printf("%c", a[i][j]);
            printf("
    ");
        }
    }
    
    void rotate_90(char a[][15])
    {
        //debug(a);
        char b[15][15];
        int ii=0, jj=0;
        for(int j=0; j<n; j++)
            for(int i=n-1; i>=0; i--)
            {
                b[ii][jj++] = a[i][j];
                if(jj == n) ii++, jj=0;
            }
        memcpy(a, b, sizeof(b));
        //debug(a);
    }
    
    void reflection(char a[][15])
    {
        //debug(a);
        for(int i=0; i<n; i++)
            for(int j=0; j<n/2; j++)
            {
                swap(a[i][j], a[i][n-1-j]);
            }
        //debug(a);
    }
    
    
    int main()
    {
        freopen("transform.in", "r", stdin);
        freopen("transform.out", "w", stdout);
        while(scanf("%d", &n) == 1)
        {
            for(int i=0; i<n; i++)    scanf("%s", s[i]);
            for(int i=0; i<n; i++)  scanf("%s", e[i]);
            memcpy(tps, s, sizeof(s));
            //rotate_90(tps);
            //reflection(tps);
            int res = 0x3f3f3f3f;
            if(IsSame(tps, e))
                res = min(res, 6);
            if(rotate_90(tps), IsSame(tps, e))
                res = min(res, 1);
            if(rotate_90(tps), IsSame(tps, e))
                res = min(res, 2);
            if(rotate_90(tps), IsSame(tps, e))
                res = min(res, 3);
            rotate_90(tps);
            reflection(tps);
            if(IsSame(tps, e))
                res = min(res, 4);
            for(int i=0; i<3; i++)
            {
                rotate_90(tps);
                if(IsSame(tps, e)) res = min(res, 5);
            }
            if(res != 0x3f3f3f3f)
                printf("%d
    ", res);
            else 
                printf("7
    ");
        }
        return 0;
    }
  • 相关阅读:
    uni-app调用原生的文件系统管理器(可选取附件上传)
    uni-app图片压缩转base64位 利用递归来实现多张图片压缩
    解释器模式
    外观模型
    装饰模式
    组合模式
    原型模式
    简单工厂模式
    抽象工厂模式
    工厂方法模式
  • 原文地址:https://www.cnblogs.com/xingxing1024/p/5058260.html
Copyright © 2011-2022 走看看