CF 990D Graph And Its Complement 第十八 构造、思维
2 seconds
256 megabytes
standard input
standard output
Given three numbers n,a,bn,a,b. You need to find an adjacency matrix of such an undirected graph that the number of components in it is equal to aa, and the number of components in its complement is bb. The matrix must be symmetric, and all digits on the main diagonal must be zeroes.
In an undirected graph loops (edges from a vertex to itself) are not allowed. It can be at most one edge between a pair of vertices.
The adjacency matrix of an undirected graph is a square matrix of size nn consisting only of "0" and "1", where nn is the number of vertices of the graph and the ii-th row and the ii-th column correspond to the ii-th vertex of the graph. The cell (i,j)(i,j) of the adjacency matrix contains 11 if and only if the ii-th and jj-th vertices in the graph are connected by an edge.
A connected component is a set of vertices XX such that for every two vertices from this set there exists at least one path in the graph connecting this pair of vertices, but adding any other vertex to XX violates this rule.
The complement or inverse of a graph GG is a graph HH on the same vertices such that two distinct vertices of HH are adjacent if and only if they are not adjacent in GG.
In a single line, three numbers are given n,a,b(1≤n≤1000,1≤a,b≤n)n,a,b(1≤n≤1000,1≤a,b≤n): is the number of vertexes of the graph, the required number of connectivity components in it, and the required amount of the connectivity component in it's complement.
If there is no graph that satisfies these constraints on a single line, print "NO" (without quotes).
Otherwise, on the first line, print "YES"(without quotes). In each of the next nn lines, output nn digits such that jj-th digit of ii-th line must be 11 if and only if there is an edge between vertices ii and jj in GG (and 00 otherwise). Note that the matrix must be symmetric, and all digits on the main diagonal must be zeroes.
If there are several matrices that satisfy the conditions — output any of them.
3 1 2
YES
001
001
110
3 3 3
NO
引用别人的题解了。。。
https://www.cnblogs.com/siuginhung/p/9172602.html
这是一个构造问题。
构造一张n阶简单无向图G,使得其连通分支个数为a,且其补图的连通分支个数为b。
对于一张n阶简单无向图G,若此图不连通,则其补图是连通的。
证明:
首先,在简单无向图G中,若结点u、v(u≠v)不连通,则在其补图中,u、v必然连通。
将图G=<V,E>划分为k个连通分支,Gi=<Vi,Ei>,i=1,2,...,k。在V中任取两点u、v(u≠v)。
若u∈Vi,v∈Vj,且i≠j,则u、v在图G中不连通,则u、v必然在其补图中连通;
若u,v∈Vi,则必然存在w∈Vj,且i≠j,使得u、w和v、w在补图中连通。
于是,在题中,a、b中至少有一个为1。
接下来构造连通分支:若一个n阶简单无向图有k(k≥2)个连通分支,则可以构造其连通分支分别为{1},{2},...,{k-1},{k,k+1,...,n}。
这是我的代码
#include <map>
#include <set>
#include <cmath>
#include <queue>
#include <cstdio>
#include <vector>
#include <string>
#include <cstring>
#include <iostream>
#include <algorithm>
#define debug(a) cout << #a << " " << a << endl
using namespace std;
const int maxn = 1e3 + ;
const int mod = 1e9 + ;
typedef long long ll;
int mapn[maxn][maxn];
int main(){
std::ios::sync_with_stdio(false);
ll n, a, b;
while( cin >> n >> a >> b ) {
bool flag = true;
if( a != && b != ) {
flag = false;
}
if( ( n == || n == ) && ( a + b == ) ) {
flag = false;
}
if( !flag ) {
cout << "NO" << endl;
continue;
}
cout << "YES" << endl;
if( b == ) {
memset( mapn, , sizeof(mapn) );
for( ll i = a; i < n; i ++ ) {
mapn[i-][i] = ;
mapn[i][i-] = ;
}
} else {
memset( mapn, -, sizeof(mapn) );
for( ll i = ; i < n; i ++ ) {
mapn[i][i] = ;
}
for( ll i = b; i < n; i ++ ) {
mapn[i-][i] = ;
mapn[i][i-] = ;
}
}
for( ll i = ; i < n; i ++ ) {
for( ll j = ; j < n; j ++ ) {
putchar( mapn[i][j] ? '' : '' );
}
putchar('\n');
}
}
return ;
}
CF 990D Graph And Its Complement 第十八 构造、思维的更多相关文章
- Codeforces 990D - Graph And Its Complement
传送门:http://codeforces.com/contest/990/problem/D 这是一个构造问题. 构造一张n阶简单无向图G,使得其连通分支个数为a,且其补图的连通分支个数为b. 对于 ...
- CodeForces 990D Graph And Its Complement(图和补图、构造)
http://codeforces.com/problemset/problem/990/D 题意: 构造一张n阶简单无向图G,使得其连通分支个数为a,且其补图的连通分支个数为b. 题解: 第一眼看到 ...
- vue第十八单元(单向数据流 vuex状态管理)
第十八单元(单向数据流 vuex状态管理) #课程目标 1.理解什么是数据管理模式 2.什么是vuex 3.什么时候使用vuex 4.vuex安装及工作原理 5.vuex语法 #知识点 1.首先来看下 ...
- Senparc.Weixin.MP SDK 微信公众平台开发教程(十八):Web代理功能
在Senparc.Weixin.dll v4.5.7版本开始,我们提供了Web代理功能,以方便在受限制的局域网内的应用可以顺利调用接口. 有关的修改都在Senparc.Weixin/Utilities ...
- Bootstrap <基础二十八>列表组
列表组.列表组件用于以列表形式呈现复杂的和自定义的内容.创建一个基本的列表组的步骤如下: 向元素 <ul> 添加 class .list-group. 向 <li> 添加 cl ...
- Bootstrap <基础十八>面包屑导航(Breadcrumbs)
面包屑导航(Breadcrumbs)是一种基于网站层次信息的显示方式.以博客为例,面包屑导航可以显示发布日期.类别或标签.它们表示当前页面在导航层次结构内的位置. Bootstrap 中的面包屑导航( ...
- 最全的MySQL基础【燕十八传世】
1.课前准备! 开启mysql服务:1).配置环境变量;2).net start mysql 将该sql文件导入到你的数据库中,以下所有操作都是基于该数据库表操作的!!! [此笔记是本人看着视频加上自 ...
- Web 前端开发人员和设计师必读文章推荐【系列二十八】
<Web 前端开发精华文章推荐>2014年第7期(总第28期)和大家见面了.梦想天空博客关注 前端开发 技术,分享各类能够提升网站用户体验的优秀 jQuery 插件,展示前沿的 HTML5 ...
- Web 前端开发精华文章集锦(jQuery、HTML5、CSS3)【系列十八】
<Web 前端开发精华文章推荐>2013年第六期(总第十八期)和大家见面了.梦想天空博客关注 前端开发 技术,分享各种增强网站用户体验的 jQuery 插件,展示前沿的 HTML5 和 C ...
随机推荐
- maven项目引用错误 和项目结构问题
解决办法: 鼠标右键 maven ---->update prroject Configuration 然后 maven clean maven install
- WPF控件截图
//截图 RenderTargetBitmap RenderVisaulToBitmap(Visual vsual, int width, int height) { ...
- Eclipse中代码自动添加注释及代码注释模板
介绍 为了提高代码的可读性以及为了有些代码有洁癖的人的需求,我们要从学生到职业进行迈进的过程中,必须把以前的那种代码可读性不高的习惯改掉,因为我们必须要与企业接轨.. 好了,废话不多说,反正就是提升自 ...
- 【Java例题】7.3 线程题3-素数线程
3.素数线程.设计一个线程子类,依次随机产生10000个随机整数(100-999):再设计另一个线程子类,依次对每一个随机整数判断是不是素数,是则显示:然后编写主类,在主函数中定义这两个线程类的线程对 ...
- AQS之CountDownLatch、Semaphore、CyclicBarrier
CountDownLatch A synchronization aid that allows one or more threads to wait until a set of operatio ...
- dotnetcore 与 hbase 之二——thrift 客户端的制作
说明 在上一篇文章dotnetcore 与 hbase 之一--hbase 环境准备结束后,我们已经有了 hbase 数据库环境.接下来就可以利用 thrift 生成 c# hbase 客户端了.如果 ...
- 单纯的xlistview
public class MainActivity extends AppCompatActivity implements XListView.IXListViewListener{ private ...
- 深入浅出Apriori关联分析算法(一)
在美国有这样一家奇怪的超市,它将啤酒与尿布这样两个奇怪的东西放在一起进行销售,并且最终让啤酒与尿布这两个看起来没有关联的东西的销量双双增加.这家超市的名字叫做沃尔玛. 你会不会觉得有些不可思议?虽然事 ...
- Linux 下用C语言连接 sqlite
1.在 /home/ 新建一个文件夹名为 sqlite #cd /home #mkdir sqlite 2.编写C语言代码,名称为 sql.c,代码如下 // name: sql.c // This ...
- File Compression and Archiving in linux (linux 中文件的归档)
1. Compressing Files at the Shell Prompt Red Hat Enterprise Linux provides the bzip2, gzip, and zip ...