题目
输入一个n阶有限群G的二元运算表及相关的子群,输出其左陪集
(注意:按照表头元素顺序计算每个陪集,下图为G的二元运算表示例)
样例1:
输入:
6 2 (注:群的阶和子群阶)
M N P Q R S (注:此7*6阵列为群G的二元运算表红色部分内容)
N P M R S Q
P M N S Q R
M N P Q R S
S R Q P N M
Q S R M P N
R Q S N M P
P Q(注:子群H)
输出: (注:空格分隔,末尾字符也有空格)
P Q (注:这是原来的子群H)
M R (注:用M乘以H中的对应每个元素)
N S (注:用N乘以H中的对应每个元素)
样例2:
输入:
6 3
M N P Q R S
N P M R S Q
P M N S Q R
M N P Q R S
S R Q P N M
Q S R M P N
R Q S N M P
M N P
输出:
M N P
S R Q
先要明确这几个问题
1.左陪集是什么
左陪集是一些集合
∀
g
∈
G
,
{
g
∗
h
∣
h
∈
H
}
\forall g \in G, \{g*h|h \in H\}
∀g∈G,{g∗h∣h∈H}
2.不相同的左陪集有几个
∣
G
∣
∣
H
∣
\frac{|G|}{|H|}
∣H∣∣G∣
代码
#include<iostream>
#include <string.h>
using namespace std;
int locate_element(char* L, char e) {
for (int i=0; i<strlen(L);i++)
if(L[i] == e)
return i;
return -1;
}
void delete_element(char* L, int i) {
int j;
for(j=i; j<strlen(L);j++)
L[j]=L[j+1];
L[j] = '\0';
}
int main()
{
int i, j, k; //循环变量
int ordG, ordH; //G和H的阶数
char tableG[100][100]; //G运算表
char G[100]; //G
char H[100]; //H
char ch;
int count;
cin>>ordG>>ordH;
for(i=0;i<ordG+1;i++) {
if(i==0) {
count = 0;
ch = ' ';
while ( count < ordG && ch != EOF ) {
cin >> ch;
if ( ch != '\r' && ch != '\n' && ch != ' ' && ch != '\t' )
G[count++] = ch;
}
}
else {
count = 0;
ch = ' ';
while ( count < ordG && ch != EOF ) {
cin >> ch;
if ( ch != '\r' && ch != '\n' && ch != ' ' && ch != '\t' )
tableG[i-1][count++] = ch;
}
}
}
count = 0;
ch = ' ';
while ( count < ordH && ch != EOF ) {
cin >> ch;
if ( ch != '\r' && ch != '\n' && ch != ' ' && ch != '\t' )
H[count++] = ch;
}
int geshu=ordG/ordH;
char G_copy[100] = {'0'};
strcpy(G_copy, G);
//cout << "Remove H from G: "<<ordH<<endl;
for(i=0; i<ordH; i++) {
// Remove H from G
char h = H[i];
cout << H[i] << " ";
int h_i = locate_element(G_copy, h);
delete_element(G_copy,h_i);
//cout << G_copy<<endl;
}
cout << endl;
for(j=0; j<geshu-1; j++) {
/*
print gH and Remove gH from G
g = G[0]
h∈H, g*h = ? Remove ? from G
*/
//cout << "Remove gH from G: \n";
char g = G_copy[0];
int g_i = locate_element(G,g);
for(k=0; k<ordH; k++) {
char h = H[k];
int h_i = locate_element(G, h);
cout << tableG[g_i][h_i] << " ";
int gh_i = locate_element(G_copy, tableG[g_i][h_i]);
//cout <<"g="<<g<<"\th="<<h<<"\tg*h="<<tableG[g_i][h_i]<<endl;
//cout <<"g_i="<<g_i<<"\th_i="<< h_i<<"\tgh_i="<<gh_i<<endl;
delete_element(G_copy, gh_i);
//cout << G_copy<<endl;
}
cout << endl;
}
return 0;
}