| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 3063 人关注过本帖
标题:[求助]判断一个二元关系是不是自反的和对称的
只看楼主 加入收藏
wq86731
Rank: 1
等 级:新手上路
帖 子:2
专家分:0
注 册:2005-12-18
收藏
 问题点数:0 回复次数:3 
[求助]判断一个二元关系是不是自反的和对称的
一道离散数学的编程题目。大家帮帮忙啊。。。

程序功能:判断一个二元关系是不是自反的和对称的。

输出:Please enter the number of the elements of the domain set:

输入:二元关系所在域的元素的个数(必须是数字)

输出:Please enter the elements of the domain set:

输入:域的元素(必须是数字)

输出:Please enter the number of the elements of the relation R:

输入:二元关系中元素的个数(必须是数字)

输出:Please enter the elements of the relation R:

输入:二元关系的元素(必须是数字组合,不用逗号间隔,不用括号,直接输入数字,中间用空格间隔,元素之间用换行间隔即可)例如:

1 1

2 2

输出:The Relation R is( not )reflexive.

The Relation R is( not )symmetic.


搜索更多相关主题的帖子: 离散数学 elements 关系 Please 数字 
2007-01-02 16:09
soft_wind
Rank: 3Rank: 3
等 级:新手上路
威 望:8
帖 子:1430
专家分:0
注 册:2006-4-5
收藏
得分:0 

假设元素为x1,x2,x3,...,xn
若关系R要满足自反且对称,则有:
(x1,x1),(x2,x2),...,(xn,xn)属于R,//自反
再循环判断其他的(x,y),其中,x!=y.
如果有xRy,则要求有yRx.即(x,y)属于R与(y,x)属于R的同或为真。


对不礼貌的女生收钱......
2007-01-02 19:21
nuciewth
Rank: 14Rank: 14Rank: 14Rank: 14
来 自:我爱龙龙
等 级:贵宾
威 望:104
帖 子:9786
专家分:208
注 册:2006-5-23
收藏
得分:0 
补充一下,就是某一对不存在时,直接可以判断不满足这个性质.
比如判断对称时<x,y>属于R,但找不到<y,x>属于R,则可以判定不满足对称这个性质.

倚天照海花无数,流水高山心自知。
2007-01-02 19:43
soft_wind
Rank: 3Rank: 3
等 级:新手上路
威 望:8
帖 子:1430
专家分:0
注 册:2006-4-5
收藏
得分:0 
平时很少做离散题,练练
[CODE]

#include <stdio.h>
#include <string.h>
#include <stdlib.h>
int locate(int *element,int len,int value)
{
for(int i=0;i<len;i++)
if(element[i]==value)
return i;
return -1;
}
int main()
{
int i,n,m,x,y,px,py;
int *element=NULL;
bool *relation=NULL;
bool isReflexive=true;
bool isSymmetic=true;
printf("Please enter the number of the elements of the domain set:\n");
scanf("%d",&n);
element=(int *)malloc(sizeof(int)*n);//添加检查内存申请是否成功
printf("Please enter the elements of the domain set:\n");
for(i=0;i<n;i++)
scanf("%d",element+i);
relation=(bool *)malloc(sizeof(bool)*n*n);//添加检查内存申请是否成功
memset(relation,false,sizeof(bool)*n*n);
printf("Please enter the number of the elements of the relation R:\n");
scanf("%d",&m);
printf("Please enter the elements of the relation R:\n");
for(i=0;i<m;i++)
{
scanf("%d%d",&x,&y);
px=locate(element,n,x);
py=locate(element,n,y);
if(px>=0&&py>=0)
relation[px*n+py]=true;
else
{
printf("Wrong Input!\n");
exit(1);
}
}
for(i=0;i<n&&relation[i*n+i]==true;i++);
if(i<n)
isReflexive=false;
for(i=0;i<n*n;i++)
{
px=i/n;
py=i%n;
if(relation[i]&&relation[py*n+px]||!relation[i]&&!relation[py*n+px]);//判断同或
else
{
isSymmetic=false;
break;
}
}
if(isReflexive)
printf("The Relation R is reflexive.\n");
else printf("The Relation R is not reflexive.\n");
if(isSymmetic)
printf("The Relation R is symmetic.\n");
else printf("The Relation R is not symmetic.\n");
return 0;
}

[/CODE]

对不礼貌的女生收钱......
2007-01-02 19:47
快速回复:[求助]判断一个二元关系是不是自反的和对称的
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.014266 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved