当前位置:网站首页>Njupt Nanyou Discrete Mathematics_ Experiment 3
Njupt Nanyou Discrete Mathematics_ Experiment 3
2022-06-11 00:10:00 【Retreat drum ten level performer】
Content :
Find the set A On the division relationship R The corresponding covering relation , And determine the poset <A,R> Whether it is a case , If case , Judge whether it is a complemented lattice .
requirement :
aggregate A It can be any set of positive integers given by the user .
package exp03;
import java.util.*;
import java.util.stream.Collectors;
class Poset {
int A[]; // aggregate
int R[][]; // The relational matrix
public Poset(int[] a) {
A = a;
// Initialize the relationship matrix
R=new int[A.length][A.length];
for(int i = 0; i < A.length; i++){
for(int j = 0; j < A.length; j++){
if(A[j] % A[i] == 0){
// If it satisfies the divisible relation , Set it to 1
R[i][j] = 1;
}
}
}
}
// Seek to cover the relationship
public void displayCOVER() {
int matrixs[][]=R; // A binary array used to determine the covering relationship
for(int i = 0; i < A.length; i++){
for(int j = 0; j <A.length; j++){
for(int k = 0; k <A.length; k++){
matrixs[k][k] = 0; // Get rid of reflexivity
if(matrixs[i][j]==1 && matrixs[j][k]==1){
matrixs[i][k] = 0; // Remove transitivity
}
}
}
}
System.out.print("COV A={");
for(int i = 0; i <A.length; i++){
for(int j = 0; j <A.length; j++){
if(matrixs[i][j]==1){
// Remove what was removed before , Others are satisfied to cover the relationship
System.out.print("<"+A[i]+","+A[j]+">,");
}
}
}
System.out.println("\b}");
}
// Judge whether it is case
public boolean isLattice(){
int Gcd=0; // greatest common divisor
int Lcm=0; // Minimum common multiple
boolean flag=true;
List<Integer> list = Arrays.stream(A).boxed().collect(Collectors.toList()); // Convert to a collection for easy query of elements
for(int i=0;i<A.length;i++)
{
for (int j=0;j<A.length;j++)
{
if(i==j)
continue;
Gcd = gcd(A[i],A[j]); // Find the maximum lower bound
Lcm = A[i] / Gcd * A[j]; // Find the minimum upper bound
// Traverse A, if Gcd and Lcm All in A in , For Grid
if(!(list.contains(Gcd)&&list.contains(Lcm)))
{
return false;
}
}
}
return flag;
}
// Find the greatest common divisor
private int gcd(int x, int y) {
int m;
// division
do{
m = x % y;
x = y;
y = m;
}while(m != 0);
return x;
}
public boolean isComplementedLattice() {
int Gcd=0; // greatest common divisor
int Lcm=0; // Minimum common multiple
boolean flag;
List<Integer> list = Arrays.stream(A).boxed().collect(Collectors.toList()); // Convert to a collection for easy query of elements
Collections.sort(list);
for(int i=0;i<A.length;i++)
{
flag=false;
for (int j=0;j<A.length;j++)
{
if(i==j)
continue;
Gcd = gcd(A[i],A[j]); // Find the maximum lower bound
Lcm = A[i] / Gcd * A[j]; // Find the minimum upper bound
// Bounded lattices
if( (Gcd==list.get(0)) && (Lcm==list.get(list.size()-1)))
{
flag = true;
break;
}
}
if(!flag){
return false;
}
}
return true;
}
}
package exp03;
import java.util.Scanner;
public class Test03 {
public static void main(String[] args) {
System.out.println(" Please enter a positive integer set A:");
// Convert user input into an array
Scanner inA = new Scanner(System.in);
String stringA[] = inA.nextLine().split(" ");
int num[] = new int[stringA.length];
for (int i = 0; i < stringA.length; i++) {
num[i] = Integer.parseInt(stringA[i]);
//System.out.println(stringA[i]);
}
// Initialize poset
Poset poset=new Poset(num);
poset.displayCOVER();
if (poset.isLattice()){
System.out.println("<A,R> It's Ge ");
if(poset.isComplementedLattice())
System.out.println("<A,R> There are complements ");
else
System.out.println("<A,R> There is no complement ");
}else
System.out.println("<A,R> Not a case ");
}
}


边栏推荐
- MP框架基本操作(自用)
- 【颜值检测神器】来,请拿出你们的绝活(这颜值,对得起观众么?)
- Why is the website snapshot hijacked and tampered with
- Openresty installation
- vtk. VTP download in JS
- csdn每日一练——找出最接近元素并输出下标
- 数据库表结构
- 【数学】【连续介质力学】流体力学中的对称张量、应变张量和应力张量
- [opencv practice] this seal "artifact" is awesome, saving time and improving efficiency. It is powerful ~ (complete source code attached)
- Difference between oscilloscope and spectrum analyzer
猜你喜欢

都说验证码是爬虫中的一道坎,看我只用五行代码就突破它。

763. 划分字母区间
![[mathematics] [continuum mechanics] symmetry tensor, strain tensor and stress tensor in fluid mechanics](/img/13/210ed249dfa3010bf69fead8e06f1b.png)
[mathematics] [continuum mechanics] symmetry tensor, strain tensor and stress tensor in fluid mechanics

【JVM】线程

【AI出牌器】第一次见这么“刺激”的斗地主,胜率高的关键因素竟是......

Opencv实战之图像的基本操作:这效果出来惊艳了众人(附代码解析)

From the perspective of Confucius Temple IP crossover, we can see how the six walnuts become "butterflies" for the second time

Bluetooth development (8) -- avdtp connection process

From the perspective of Confucius Temple IP crossover, we can see how the six walnuts become "butterflies" for the second time

【Pygame小游戏】这款“打地鼠”小游戏要火了(来来来)
随机推荐
插入排序
It is said that the verification code is a barrier in the crawler. I can break through it with only five lines of code.
启牛学堂理财可靠吗,安全吗
sql 语句--输入 月份 查日期(年月日),输出 月份
【Pygame合集】滴~穿越童年游戏指南 请查收:这里面有你玩过的游戏嘛?(附五款源码自取)
[opencv practice] in cold winter, there will be a rainbow. Do you love this special effect?
763. 划分字母区间
【 pygame Games 】 don't find, Leisure Games Theme come 丨 Bubble Dragon applet - - Leisure Games Development recommendation
【Pygame小游戏】不怕你走不过系列:极致AI走迷宫,学习完带你打开新世界大门~(附游戏源码)
【Pygame小游戏】Chrome上的小恐龙竟可以用代码玩儿了?它看起来很好玩儿的样子~
csdn每日一练——找出最接近元素并输出下标
希尔排序
【Pygame小游戏】《坦克大战》,那些童年的游戏你还记得几个呢?
Bluetooth development (11) -- ble interacts happily
curl导入postman报错小记
Method of converting file to multipartfile
ASP. Net programming version C (notes along with learning progress)
安全生产月,黄埔开展燃气安全进商铺宣传活动
2022 college entrance examination quantitative paper | please answer the questions for quantitative candidates
The same customized right-click menu beautification on this site - Xingze V Club