• USACO Section 1.2 Transformations


    北航复试题是此题的简化,如果不是文件操作这题早就过了

    /*
     ID:linyvxi1
     LANG:C++
     TASK:transform
    */
    //#include <stdio.h>
    //#include <iostream>
    #include <fstream>
    #include <string.h>
    using namespace std;
    int N;
    char mat1[11][11],mat2[11][11];
    char mat3[11][11];
    bool degree_90()
    {
    	int i,j;
    	for(i=1;i<=N;i++){
    		for(j=1;j<=N;j++)
    			if(mat1[i][j]!=mat2[j][N-i+1])
    				return false;
    	}
    	return true;
    }
    
    bool degree_180()
    {
    	int i,j;
    	for(i=1;i<=N;i++)
    		for(j=1;j<=N;j++)
    			if(mat1[i][j]!=mat2[N-i+1][N-j+1])
    				return false;
    	return true;
    }
    
    bool degree_270()
    {
    	int i,j;
    	for(i=1;i<=N;i++)
    		for(j=1;j<=N;j++)
    			if(mat1[i][j]!=mat2[N-j+1][i])
    				return	false;
    	return true;
    }
    
    bool same()
    {
    	int i,j;
    	for(i=1;i<=N;i++)
    		for(j=1;j<=N;j++)
    			if(mat1[i][j]!=mat2[i][j])
    				return false;
    	return true;
    }
    
    bool refle()
    {
    	int i,j;
    	if(N%2==0){
    		for(i=1;i<=N;i++)
    			for(j=1;j<=N/2;j++)
    				if(mat1[i][j]!=mat2[i][N-j+1])
    					return	false;
    		return true;
    	}
    	else{
    		for(i=1;i<=N;i++)
    			if(mat1[i][N/2+1]!=mat2[i][N/2+1])
    				return false;
    		for(i=1;i<=N;i++)
    			for(j=1;j<=N/2;j++)
    				if(mat1[i][j]!=mat2[i][N-j+1])
    					return false;
    		return true;
    	}
    	return false;
    }
    
    bool f()
    {
    	int i,j;
    	for(i=1;i<=N;i++){
    			for(j=1;j<=N;j++)
    				mat3[i][j]=mat1[i][N-j+1];
    	}
    	for(i=1;i<=N;i++)
    		for(j=1;j<=N;j++)
    			mat1[i][j]=mat3[i][j];
    }
    
    
    int main()
    {
    //	FILE*	fin=fopen("transform.in","r");
    //	FILE*	fout=fopen("transform.out","w");
    	ifstream fin("transform.in");
    	int meth=7;
    //	fscanf(fin,"%d",&N);
    	fin>>N;
    //	scanf("%d",&N);
    	int i,j;
    	char temp;
    //	getchar();
    	for(i=1;i<=N;i++){
    		//fscanf(fin,"%c",&temp);
    		for(j=1;j<=N;j++)
    		//	fscanf(fin,"%c",&mat1[i][j]);
    		fin>>mat1[i][j];
    //		scanf("%c",&mat1[i][j]);
    	}
    	for(i=1;i<=N;i++){
    //		fscanf(fin,"%c",&temp);
    		for(j=1;j<=N;j++)
    //			fscanf(fin,"%c",&mat2[i][j]);
    		fin>>mat2[i][j];
    		//scanf("%c",&mat2[i][j]);
    	}
    	if(degree_90())
    		meth=1;
    	else if(degree_180())
    		meth=2;
    	else if(degree_270())
    		meth=3;
    	else if(refle())
    		meth=4;
    	else if(same())
    		meth=6;
    	else{
    		f();
    		if(degree_90()||degree_180()||degree_270())
    			meth=5;
    	}
    	ofstream fout("transform.out");
    	fout<<meth<<endl;
    	fout.close();
    }
    

    依然给出测试数据

    Here are the test data inputs:

    ------- test 1 ----
    3
    ---
    ---
    ---
    ---
    -@-
    ---
    ------- test 2 ----
    5
    -@@@-
    -@@--
    -@---
    -----
    -----
    -----
    ----@
    ---@@
    --@@@
    -----
    ------- test 3 ----
    5
    @@@@@
    @---@
    @@@@@
    @@@@@
    @@@@@
    @@@@@
    @@@@@
    @@@@@
    @---@
    @@@@@
    ------- test 4 ----
    6
    -@-@-@
    @-@-@-
    -@-@-@
    @-@-@-
    -@-@-@
    @-@-@-
    @-@-@-
    -@-@-@
    @-@-@-
    -@-@-@
    @-@-@-
    -@-@-@
    ------- test 5 ----
    3
    @@@
    ---
    @@@
    @@@
    ---
    @@@
    ------- test 6 ----
    4
    @@@@
    @@@@
    -@@@
    @@@@
    @@@@
    @@@@
    @@@-
    @@@@
    ------- test 7 ----
    4
    @-@@
    @@@@
    @@@@
    @@@@
    @@@@
    @@@@
    @@@@
    @-@@
    ------- test 8 ----
    10
    @--------@
    ----------
    ----------
    ----------
    ----------
    ----------
    ----------
    ----------
    ----------
    ----------
    @---------
    ----------
    ----------
    ----------
    ----------
    ----------
    ----------
    ----------
    ----------
    ---------@
    

  • 相关阅读:
    C# 枚举常用工具方法
    AppBox_v3.0
    DDD:四色原型中Role的 “六” 种实现方式和PHP的Swoole扩展
    MySql主从配置实践及其优势浅谈
    ActionInvoker
    【Oracle】-【体系结构】-【DBWR】-DBWR进程相关理解
    Linux MySQL单实例源码编译安装5.6
    窗口嵌入到另一个窗口(VC和QT都有)
    Window下 Qt 编译MySQL驱动(居然用到了动态库格式转换工具,需要将C:/MySQL/lib目录下的libmySQL.dll文件复制到我们Qt Creator安装目录下的qt/bin目录中)good
    在Linux下使用iconv转换字符串编码
  • 原文地址:https://www.cnblogs.com/yangce/p/2226366.html
Copyright © 2020-2023  润新知