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;
    }
    


  • 相关阅读:
    我的第一篇博客
    汇编语言——基础知识 Cop
    汇编语言第二章实验 Cop
    什么是<!DOCTYPE html>
    python第三方模块安装的几个方式
    linux下安装memcacheQ
    python正则表达式
    边框背景
    伪类
    属性选择符和样式
  • 原文地址:https://www.cnblogs.com/Jstyle-continue/p/6352039.html
Copyright © 2011-2022 走看看