偏序关系

Time Limit: 1000 ms Memory Limit: 65536 KiB

Problem Description

给定有限集上二元关系的关系矩阵,确定这个关系是否是偏序关系。

Input

多组测试数据,对于每组测试数据,第1行输入正整数n(1 <= n <= 100),第2行至第n+1行输入n行n列的关系矩阵。

Output

对于每组测试数据,若为偏序关系,则输出yes,反之,则输出no。

Sample Input

4
1 0 0 0
0 1 0 0
0 0 1 0
0 0 0 1
4
1 0 0 1
0 1 0 0
0 0 1 0
1 0 0 1

Sample Output

yes
no

Hint

偏序关系形式定义:设R是集合A上的一个二元关系,若R满足自反性、反对称性、传递性,则称R为A上的偏序关系。

#include <stdio.h>
#include <stdlib.h> int main()
{
int i, j, k, n;
int a[110][110];
while(~scanf("%d", &n))
{
int flag = 1;
for(i=0; i<n; i++)
{
for(j=0; j<n; j++)
{
scanf("%d", &a[i][j]);
}
}
for(i=0; i<n; i++)
{
if(!a[i][i])
{
flag = 0;
break;
}
for(j=0; j<n; j++)
{
if(a[i][j] && a[j][i] && i!=j)
{
flag = 0;
break;
}
if(a[i][j])
{
for(k=0; k<n; k++)
{
if(a[j][k])
{
if(!a[i][k])
{
flag = 0;
break;
}
}
}
}
}
}
if(flag) printf("yes\n");
else printf("no\n");
}
return 0;
}

【离散数学】 SDUT OJ 偏序关系的更多相关文章

  1. SDUT OJ 2607

    /*http://acm.sdut.edu.cn/sdutoj/problem.php?action=showproblem&problemid=2607*/ 题目大意:给出一个字符串,求出里 ...

  2. SDUT OJ 1221 亲和数 (找出某个数n所有的因子数,只需要暴力:2->sqrt(n) 即可 )

    亲和数 Time Limit: 1000ms   Memory limit: 65536K  有疑问?点这里^_^ 题目描述 如果a的因子和等于b,b的因子和等于a,且a≠b,则称a,b为亲和数对. ...

  3. SDUT OJ 图练习-BFS-从起点到目标点的最短步数 (vector二维数组模拟邻接表+bfs , *【模板】 )

    图练习-BFS-从起点到目标点的最短步数 Time Limit: 1000ms   Memory limit: 65536K  有疑问?点这里^_^ 题目描述 在古老的魔兽传说中,有两个军团,一个叫天 ...

  4. 【离散数学】 SDUT OJ 传递闭包 && memset 使用注意事项

    传递闭包 Time Limit: 1000 ms Memory Limit: 65536 KiB Submit Statistic Problem Description 已知有n头牛,m次战斗关系, ...

  5. 【离散数学】 SDUT OJ 建图

    建图 Time Limit: 1000 ms Memory Limit: 65536 KiB Submit Statistic Problem Description 编程使得程序可以接受一个图的点边 ...

  6. 【离散数学】SDUT OJ 指定长度路径数

    指定长度路径数 Time Limit: 1000 ms Memory Limit: 65536 KiB Submit Statistic Problem Description 题目给出一个有n个节点 ...

  7. 【离散数学】SDUT OJ 补图

    补图 Time Limit: 1000 ms Memory Limit: 65536 KiB Submit Statistic Problem Description 题目给出一个无向图,求该无向图关 ...

  8. 【离散数学】 SDUT OJ 集合的包含

    集合的包含 Time Limit: 1000 ms Memory Limit: 65536 KiB Submit Statistic Problem Description 已知含n个元素的集合的子集 ...

  9. 【离散数学】 SDUT OJ 谁是作案嫌疑人?

    谁是作案嫌疑人? Time Limit: 1000 ms Memory Limit: 65536 KiB Submit Statistic Problem Description 刑侦大队对涉及六个嫌 ...

随机推荐

  1. ZigBee协议栈中AES加密算法

    原文地址:ZigBee协议栈中AES加密算法作者:大浪淘沙 Z-stack对Zigbee2006提供了全面的支持,功能之强大,性能稳定.安全性高,说到安全性是我们今天的主题.CC2430硬件支持128 ...

  2. obj.get_字段名称_display

    在页面上我们只要这么写就可以直接把字典的值显示出来了 {{ obj.get_level_display }}({{ obj.level }}) obj.get_字段名称_display . model ...

  3. Cunit编译安装

    1.  Examples/Makefile.am:26: to 'configure.ac' and run 'autoconf' again. configure.ac:211: error: re ...

  4. 获取HTML元素位置--js学习笔记

    对于不同的元素,不同的浏览器,offsetParent含义不同,有时,指的是直接包含的元素,有时指的是HTML元素,有时不存在offsetParent. 如果所研究的元素没有offsetParent, ...

  5. 第七课 ROS的空间描述和变换

    在命令行工具中也有一个与transformcaster相类似的工具叫做static_transform_publisher,它能够接受命令行参数来接受位置信息.旋转信息.父框架.子框架以及周期信息,通 ...

  6. Maven——依赖

    一.依赖的范围 依赖的范围有几个可选值,我们用得到的是:compile.test.provided 三个. [1]从项目结构角度理解 compile 和 test 的区别 [2]从开发和运行这两个不同 ...

  7. JUnit 两日游

    从一个简单的Junit demo到一个用户名与密码的验证 学习Junit,首先肯定是要环境的搭建与配置. 第一步,安装JDK,配置环境变量 第二步,安装eclipse.OS X环境下,eclipse并 ...

  8. (转)Entity Framework 5.0系列之自动生成Code First代码

    原文地址:http://www.cnblogs.com/kenshincui/archive/2013/08/29/3290527.html 在前面的文章中我们提到Entity Framework的“ ...

  9. Codeforces 900C. Remove Extra One(暴力)

    You are given a permutation p of length n. Remove one element from permutation to make the number of ...

  10. How do I create a .pyc file?

    Python automatically compiles your script to compiled code, so called byte code, before running it. ...