• 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;
    }
  • 相关阅读:
    为自己的开篇
    软考程序员笔记
    centos php7 安装mysqli扩展心得
    php判断访问协议是否是https
    go语言新建多维map集合
    获取contenteditable区域光标所在位置信息
    ckeditor中 config.js等通过ckeditor.js引入文件手动修改方法
    Vue使用——v-for循环里面使用v-if判断显示数据
    数据库关联字段设置
    Spring Jpa 自动建表——时间字段设置
  • 原文地址:https://www.cnblogs.com/xingxing1024/p/5058260.html
Copyright © 2020-2023  润新知