补图

Time Limit: 1000 ms Memory Limit: 65536 KiB

Problem Description

题目给出一个无向图,求该无向图关于完全图的相对补图,并求该补图的最大度和最小度。方便起见,用邻接矩阵表示该无向图。无向图的节点数不少于2并且不超过500.

Input

多组输入,每组输入第一行是无向图中节点的数量即邻接矩阵的行列数n。接下来n行n列为该图的邻接矩阵。

Output

每组数据,首先输出n行n列表示补图的邻接矩阵。接下来一行两个用空格分隔的整数,分别代表补图的最大度和最小度。

Sample Input

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

Sample Output

0 1 0 0
1 0 1 0
0 1 0 1
0 0 1 0
2 1
#include <stdio.h>
#include <stdlib.h>
#define MA 550 int main()
{
int n;
int G[MA][MA];
int i, j;
int max, min;
int deg;
while(~scanf("%d", &n))
{
max = 0;
min = MA;
for(i=0; i<n; i++)
{
deg = 0; //初始化每个节点的度数
for(j=0; j<n; j++)
{
scanf("%d", &G[i][j]);
if(i != j) //输入直接求补图该节点的边,减小时间复杂度
{
if(G[i][j] == 1)
{
G[i][j] = 0;
}
else
{
G[i][j] = 1;
}
}
if(G[i][j] == 1)
{
deg++; //计算度数
}
}
if(deg > max)
{
max = deg;
}
if(deg < min)
{
min = deg;
}
} for(i=0; i<n; i++)
{
for(j=0; j<n-1; j++)
{
printf("%d ", G[i][j]);
}
printf("%d\n", G[i][j]);
}
printf("%d %d\n", max, min);
}
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. Ubuntu16.04安装之后的几个设置

    Ubuntu16.04安装之后的几个设置 Ubuntu16.04界面很漂亮,但是安装之后,需要做如下几个简单的设置,这样用的时候会更加顺畅. 1.中文支持 在右上角有一个齿轮,点击->Syste ...

  2. linux下配置tomcat开机自启动

    Linux下配置tomcat开机自启动   1.写一个tomcat脚本,内容如下,设置其权限为755,放在/etc/init.d/目录下 #!/bin/bash## /etc/init.d/tomca ...

  3. web页面在ios下不支持fixed可用absolute替代的方案

    本文引用出处:http://www.cnblogs.com/PeunZhang/p/3553020.html. 对于 ios4 和 android2.2 以下不支持 position:fixed 的问 ...

  4. collections、time和datetime模块

    主要内容: 一.collections模块 二.time模块 三.datetime模块 1️⃣  collection模块 1.什么是collections模块.干什么用? collections模块 ...

  5. Entitlements

    [Entitlements] Entitlements confer specific capabilities or security permissions to your iOS or OS X ...

  6. Reporting Service中配置oracle 数据连接

    一.安装配置报表服务器 数据源 1.安装oracle客户端32位“Oracle - OraClient11g_home1_32bit” 2.配置监听及tnsnames.ora 3.配置ODBC 添加一 ...

  7. zookeeper全局数据一致性及其典型应用(发布订阅、命名服务、帮助其他集群选举)

    ZooKeeper全局数据一致性: 全局数据一致:集群中每个服务器保存一份相同的数据副本,client 无论连接到哪个服务器,展示的数据都是一致的,这是最重要的特征. 那么zookeeper集群是怎样 ...

  8. NODEJS网站

    nodejs https://nodejs.org/en/ nodejs官网 http://nodeapi.ucdok.com/#/api/ nodejs手册 https://www.npmjs.co ...

  9. 粗粒度(Coarse-grained)vs细粒度(fine-grained)

    在读的一篇文献中关于RDF的描述: As we know, RDF data is a set of triples with the form (subject, property, object) ...

  10. Luogu 2597 [ZJOI2012]灾难

    BZOJ 2815. 解法还是挺巧妙的. 放上写得很详细很好懂的题解链接  戳这里. 一个物种$x$如果要灭绝,那么沿着它的入边反向走走走,一定可以走到一个点$y$,如果这个点$y$的物种灭绝了,那么 ...