| 编程中国 | 业界新闻 | 技术文章 | 视频教程 | 下载频道 | 程序源码 | 个人空间 | 编程论坛
全能ASP/PHP/ASP.NET主机,支持月付专业 MSSQL 数据库空间,支持月付专业 MySQL 数据库空间,支持月付买域名,送MP3、MP4
高端软件开发 = 年薪十万不是梦赛孚耐:软件保护加密专家身份认证令牌USB KEY买空间,免费送域名(厦门中资源)
共有 342 人关注过本帖
标题:[求助]判断一个二元关系是不是自反的和对称的
收藏  订阅  推荐  打印 
wq86731
Rank: 1
等级:新手上路
帖子:2
积分:120
注册:2005-12-18
[求助]判断一个二元关系是不是自反的和对称的

一道离散数学的编程题目。大家帮帮忙啊。。。

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

输出: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-1-2 16:09
soft_wind
Rank: 6Rank: 6
等级:金牌会员
威望:8
帖子:1430
积分:14400
注册:2006-4-5

假设元素为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-1-2 19:21
nuciewth
Rank: 12Rank: 12Rank: 12
来自:我爱龙龙
等级:版主
威望:93
帖子:9525
积分:95102
注册:2006-5-23

补充一下,就是某一对不存在时,直接可以判断不满足这个性质.
比如判断对称时<x,y>属于R,但找不到<y,x>属于R,则可以判定不满足对称这个性质.

倚天照海花无数,流水高山心自知。
2007-1-2 19:43
soft_wind
Rank: 6Rank: 6
等级:金牌会员
威望:8
帖子:1430
积分:14400
注册:2006-4-5

平时很少做离散题,练练
[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-1-2 19:47
关于我们 | 广告合作 | 编程中国 | 清除Cookies | Archiver | WAP | TOP

编程中国 版权所有,并保留所有权利。鲁ICP备08000592号
Powered by Discuz, Processed in 0.069356 second(s), 9 queries.
Copyright©2004-2008, BCCN.NET, All Rights Reserved