zoukankan      html  css  js  c++  java
  • 判定同态和其基本定义

    判定同态

    基本定义


    简单的代码实现(代码写的真的很简单,离散数学更应该注重定义的理解)

    输入样例

    3//A={1,2,3}上的运算——运算表表示
    1 2 3 
    2 1 3
    3 2 1
    
    3//B={1,2,3}上的运算——运算表表示
    1 2 3 
    1 2 3 
    1 2 3
    
    4 //4个A到B的函数
    1 2 3 //A:1,2,3 对应映射到 B:1,2,3
    1 1 1 //A:1,2,3 对应映射到 B:1,1,1
    2 3 1 //A:1,2,3 对应映射到 B:2,3,1
    2 1 3 //A:1,2,3 对应映射到 B:2,1,3
    

    输出样例

    algebra A:
    1 2 3
    2 1 3
    3 2 1
    algebra B:
    1 2 3
    1 2 3
    1 2 3
    map:1 2 3
    No
    h(21) = 2
    h(2)h(1) = 1
    map:1 1 1
    Yes
    map:2 3 1
    No
    h(21) = 3
    h(2)h(1) = 2
    map:2 1 3
    No
    h(21) = 1
    h(2)h(1) = 2
    

    代码实现

    #include <iostream>
    using namespace std;
    int main(){
        int size1;
        cout<<"The size of the matrix1:"<<endl;
        cin>>size1;
        int size2;
        cout<<"The size of the matrix2:"<<endl;
        cin>>size2;
        //初始化运算表
        int matrix1[10][10] = {0};
        int matrix2[10][10] = {0};
        printf("algebra A:
    ");
        for(int i = 1; i <= size1; i++){
            for(int j = 1; j <= size1; j++){
               cin>>matrix1[i][j];
            }
        }
         printf("algebra B:
    ");
        for(int i = 1; i <=size2; i++){
            for(int j = 1; j <= size2; j++){
                cin>>matrix2[i][j];
            }
        }
    	
    	cout<<"the num of maps:"<<endl;
        int num;
        cin>>num;//映射次数
        int arr[size1+1] ={0};//分别是代数A的1,2,3的映射
        for(int k= 0;k<num;k++){
        	printf("map: ");
          	for(int i = 1;i<=size1; i++){
          		cin>>arr[i];
    		  }
    		  int flag = 1;
            //进行判断是否符合同态
            for(int i = 1; i <= size1; i++){
            	for(int j = 1; j <= size1;j ++){
            		if(arr[matrix1[i][j] ] != matrix2[arr[i]][arr[j]] && flag ==1 ){
            			printf("No
    ");
            			printf("h(%d%d)=%d
    ",i,j,arr[matrix1[i][j] ]);
            			printf("h(%d)(%d)=%d
    ",i,j,matrix2[arr[i]][arr[j]]);
            			flag =0;
    				}
    			}
    		}
    		if(flag == 1)printf("Yes
    ");
            
        }
    }
    

    在这基础上进行修改,可得判断是否同构的代码

    #include <iostream>
    using namespace std;
    int main(){
        int size1;
        cout<<"The size of the matrix1:"<<endl;
        cin>>size1;
        //初始化运算表
        int matrix1[10][10] = {0};
        printf("algebra A:
    ");
        for(int i = 1; i <= size1; i++){
            for(int j = 1; j <= size1; j++){
               cin>>matrix1[i][j];
            }
        }
    	
    	cout<<"the num of maps:"<<endl;
        int num;
        cin>>num;//映射次数
        int arr[size1+1] ={0};//分别是代数A的1,2,3的映射
        for(int k= 0;k<num;k++){
        	printf("map: ");
          	for(int i = 1;i<=size1; i++){
          		cin>>arr[i];
    		  }
    		  int flag = 1;
            //进行判断是否符合自同构
            for(int i = 1; i <= size1; i++){
            	for(int j = 1; j <= size1;j ++){
            		if(arr[matrix1[i][j] ] != matrix1[arr[i]][arr[j]] && flag ==1 ){
            			printf("No
    ");
            			printf("h(%d%d)=%d
    ",i,j,arr[matrix1[i][j] ]);
            			printf("h(%d)(%d)=%d
    ",i,j,matrix1[arr[i]][arr[j]]);
            			flag =0;
    				}
    			}
    		}
    		if(flag == 1)printf("Yes
    ");
            
        }
    }
    
  • 相关阅读:
    【Azure】Azure 命令行接口 (CLI)
    【Git】敏感信息保护
    【LeetCode】31.下一个排列
    【LeetCode】26.删除排序数组中的重复项
    【LeetCode】16. 最接近的三数之和
    【LeetCode】15.三数之和
    工作中常用的 JVM 配置参数有哪些?
    Java面试突击100题
    Java奇淫异术
    Linux 大文件按大小切割,合并还原
  • 原文地址:https://www.cnblogs.com/miaomiaolan/p/13050030.html
Copyright © 2011-2022 走看看