题意:

给定点数,构造自补图,要求输出邻接矩阵,和原图与补图的同构映射。

题解:

只有点数为4k和4k+1的情况才能构造自补图,因为只有这些情况下边数才为偶数。

一种构造方式是,邻接矩阵和同构映射增量构造,每次加四个边xyzw,x和w连接原来的所有边,yz不连,同构映射是交换xy,zw

参考:www.matrix67.com/blog/archives/6221

#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
const int M = 2e3 + ;
const LL mod = ;
const LL lINF = 0x3f3f3f3f3f3f3f3f;
bool mp[M][M];
int t;
int n;
int a[M];
int main()
{
scanf("%d", &t);
for (int cnt = ; cnt <= t; cnt++)
{
scanf("%d", &n);
if (n % == )
{
printf("Case #%d: Yes\n", cnt);
memset(mp, , sizeof mp);
mp[][] = mp[][] = ;
mp[][] = mp[][] = ;
mp[][] = mp[][] = ;
a[] = ;
a[] = ;
a[] = ;
a[] = ;
for (int i = ; i <= n; i += )
{
mp[i][i + ] = mp[i + ][i] = ;
mp[i + ][i + ] = mp[i + ][i + ] = ;
mp[i + ][i + ] = mp[i + ][i + ] = ;
for (int j = ; j < ; j+=)
{
for (int k = ; k < i; k++)
{
mp[i + j][k] = mp[k][i + j] = ;
}
}
a[i] = i + ;
a[i + ] = i;
a[i + ] = i + ;
a[i + ] = i + ;
swap(a[i+], a[i + ]);
}
for (int i = ; i <= n; i++)
{
for (int j = ; j <= n; j++)
{
printf("%d", mp[i][j]);
}
puts("");
}
for (int i = ; i < n; i++)
{
printf("%d ", a[i]);
}
printf("%d\n", a[n]);
}
else if (n % == )
{
printf("Case #%d: Yes\n", cnt);
memset(mp, , sizeof mp);
a[] = ;
for (int i = ; i <= n; i += )
{
mp[i][i + ] = mp[i + ][i] = ;
mp[i + ][i + ] = mp[i + ][i + ] = ;
mp[i + ][i + ] = mp[i + ][i + ] = ;
for (int j = ; j < ; j+=)
{
for (int k = ; k < i; k++)
{
mp[i + j][k] = mp[k][i + j] = ;
}
}
a[i] = i + ;
a[i + ] = i;
a[i + ] = i + ;
a[i + ] = i + ;
swap(a[i+], a[i + ]);
}
for (int i = ; i <= n; i++)
{
for (int j = ; j <= n; j++)
{
printf("%d", mp[i][j]);
}
puts("");
}
for (int i = ; i < n; i++)
{
printf("%d ", a[i]);
}
printf("%d\n", a[n]);
}
else
{
printf("Case #%d: No\n", cnt);
}
}
}

牛客多校第六场 E Androgynos 自补图的更多相关文章

  1. 牛客多校第六场 C Generation I 组合数学 阶乘逆元模板

    链接:https://www.nowcoder.com/acm/contest/144/C来源:牛客网 Oak is given N empty and non-repeatable sets whi ...

  2. 牛客多校第六场 J Heritage of skywalkert 随即互质概率 nth_element(求最大多少项模板)

    链接:https://www.nowcoder.com/acm/contest/144/J来源:牛客网 skywalkert, the new legend of Beihang University ...

  3. 牛客多校第六场-H-Pair

    链接:https://ac.nowcoder.com/acm/contest/887/H来源:牛客网 题目描述 Given three integers A, B, C. Count the numb ...

  4. 同构图+思维构造——牛客多校第六场E

    考的其实是同构图的性质: 1.同构图的顶点数,边数相等 2.同构图通过点的映射后邻接矩阵相同 这篇博客讲的很好https://www.jianshu.com/p/c33b5d1b4cd9 本题还需要一 ...

  5. 2018牛客多校第六场 G.Pikachu

    题意: 给出一棵n个点的树,每条边有边权.对这个树加边变成一个完全图.新加的边的权值为边上两点在树上的距离.求完全图上任意两点的最大流之和. 题解: 一共有C(n,2)个点对.假设当前求s到t之间的最 ...

  6. 2018牛客多校第六场 I.Team Rocket

    题意: 给出n个区间和m个点(点按顺序给出且强制在线).每个区间只会被第一个他包含的点摧毁.问每个点能摧毁多少个区间以及每个区间是被哪个点摧毁的. 题解: 将n个区间按照左端点排序,然后用vector ...

  7. 牛客多校第六场C

    一个数很大,并不能预处理,所以要进行公式变换,存前一个的值就好 #include <bits/stdc++.h> using namespace std; typedef long lon ...

  8. Palindrome Mouse(2019年牛客多校第六场C题+回文树+树状数组)

    目录 题目链接 题意 思路 代码 题目链接 传送门 题意 问\(s\)串中所有本质不同的回文子串中有多少对回文子串满足\(a\)是\(b\)的子串. 思路 参考代码:传送门 本质不同的回文子串肯定是要 ...

  9. 2019牛客多校第六场 B - Shorten IPv6 Address 模拟

    B - Shorten IPv6 Address 题意 给你\(128\)位的二进制,转换为十六进制. 每\(4\)位十六进制分为\(1\)组,每两组用一个\(":"\)分开. 每 ...

随机推荐

  1. springmvc3.2集成redis集群

    老项目需要集成redis集群 因为spring版本才从2.x升级上来,再升级可能改动较大,且并非maven项目升级麻烦,故直接集成. jar包准备: jedis-2.9.0.jar  -- 据说只有这 ...

  2. while循环和for循环

    while循环 n='我怎么那么可爱呀' count= while count<len(n): print(n[count]) count+= for循环 n='我怎么那么可爱呀' for i ...

  3. AWS lambda DynamoDB api gateway之间的连接

    创建角色 附加策略 AmazonDynamoDBFullAccess AWSLambdaDynamoDBExecutionRole 创建DynamoDB表 在表的项目中创建内容 this pipi 打 ...

  4. volatile的使用及其原理

    1. volatile的作用 相比Sychronized(重量级锁,对系统性能影响较大),volatile提供了另一种解决 可见性和有序性 ???问题的方案.对于原子性,需要强调一点,也是大家容易误解 ...

  5. BIO、NIO和AIO

    BIO(Blocking I/O)同步阻塞I/O 这是最基本与简单的I/O操作方式,其根本特性是做完一件事再去做另一件事,一件事一定要等前一件事做完,这很符合程序员传统的顺序来开发思想,因此BIO模型 ...

  6. Go 算术运算符

    Go 算术运算符 package main import "fmt" func main() { var a int = 21 var b int = 10 var c int c ...

  7. 【安装】Mac rabbitMQ

    安装 brew install rabbitmq 目录  cd /usr/local/Cellar/rabbitmq/3.7.4/sbin 插件 sudo ./rabbitmq-plugins ena ...

  8. 在vue中使用handsontable

    1.使用npm安装 npm install handsontable @handsontable/vue 2.定义结构 <hot-table :settings="hotSetting ...

  9. LeetCode 1041. Robot Bounded In Circle (困于环中的机器人)

    题目标签:Math 题目让我们判断机器人是否是一直在走一个圈. 当我们把 instructions 走完一遍时候: 1. 如果机器人回到了原点,那么它是在走一个圈. 2. 如果机器人的方向没有改变,那 ...

  10. LeetCode 181. Employees Earning More Than Their Managers (超过经理收入的员工)

    题目标签: 题目给了我们一个 员工表,包括经理.员工会有经理的id. 这里可以重复 利用两次 表格,表格a, 表格b,当a 员工的经理id  等于 b员工时候,在从中找到员工工资大于经理的.具体看co ...