zoukankan      html  css  js  c++  java
  • USACO 1.2-Transformations

    /*
    ID: m1590291
    TASK: transform
    LANG: C++
    */
    #include <iostream>
    #include <fstream>
    #include <algorithm>
    #define MAX 20
    using namespace std;
    int n;
    char a[MAX][MAX],b[MAX][MAX];
    
    bool check()    //检查是否相等
    {
        bool flag=true;
    	for(int i=0;i<n;i++)
    		for(int j=0;j<n;j++)
    			if(a[i][j]!=b[i][j])
                    return false;
        return true;
    }
    void to90()    //旋转90度
    {
        char tmp[MAX][MAX];
    	for(int i=0;i<n;i++)
    		for(int j=0;j<n;j++)
    			tmp[j][n-i-1]=a[i][j];
    	for(int i=0;i<n;i++)
    		for(int j=0;j<n;j++)
    			a[i][j]=tmp[i][j];
    }
    void Ref()    //中央铅垂线翻转
    {
    	char tmp[MAX][MAX];
    	for(int i=0;i<n;i++)
    		for(int j=0;j<n;j++)
    			tmp[i][n-j-1]=a[i][j];
    	for(int i=0;i<n;i++)
    		for(int j=0;j<n;j++)
    			a[i][j]=tmp[i][j];
    }
    int main()
    {
        ifstream fin ("transform.in");
        ofstream fout ("transform.out");
        while(fin>>n)
        {
            int flag=1,ans=100;
            if(n<1 || n>10) break;
    
            for(int i=0;i<n;i++)    fin>>a[i];
            for(int i=0;i<n;i++)    fin>>b[i];
    
            for(int i=1;i<4;i++){
                to90();
                if(check() == true)
                    ans=min(ans,i);
            }
            to90();  //再次旋转90度,使图形变回原样
            if(ans>4){
                Ref();
                if(check() == true)
                    ans=4;
                else{
                    for(int i=1;i<4;i++){
                        to90();
                        if(check() == true)
                            ans=5;
                    }
                }
            }
            if(ans>5){
                if(check() == true)
                    ans=6;
                else
                    ans=7;
            }
            fout<<ans<<endl;
        }
        return 0;
    }
    


  • 相关阅读:
    ABP文档
    SqlServer英文单词全字匹配
    npm不是以管理身份运行遇到的问题
    concurrenthashmap jdk1.8
    HashSet源码分析 jdk1.6
    Iterator设计模式--jdk1.7
    代理模式
    高并发下的HashMap,ConcurrentHashMap
    HashMap源码分析jdk1.6
    Stack&Vector源码分析 jdk1.6
  • 原文地址:https://www.cnblogs.com/Jstyle-continue/p/6352039.html
Copyright © 2011-2022 走看看