未名湖附近共有N个大小湖泊L1, L2, …, Ln(其中包括未名湖),每个湖泊Li里住着一只青蛙Fi(1 ≤ i ≤ N)。如果湖泊Li和Lj之间有水路相连,则青蛙Fi和Fj互称为邻居。现在已知每只青蛙的邻居数目x1, x2, …, xn,请你给出每两个湖泊之间的相连关系。

Input

第一行是测试数据的组数T(0 ≤ T ≤ 20)。每组数据包括两行,第一行是整数N(2 < N < 10),第二行是N个整数,x1, x2,…, xn(0 ≤ xi ≤ N)。

Output

对输入的每组测试数据,如果不存在可能的相连关系,输出”NO”。否则输出”YES”,并用N×N的矩阵表示湖泊间的相邻关系,即如果湖泊i与湖泊j之间有水路相连,则第i行的第j个数字为1,否则为0。每两个数字之间输出一个空格。如果存在多种可能,只需给出一种符合条件的情形。相邻两组测试数据之间输出一个空行。

Sample Input

3
7
4 3 1 5 4 2 1
6
4 3 1 4 2 0
6
2 3 1 1 2 1

Sample Output

YES
0 1 0 1 1 0 1
1 0 0 1 1 0 0
0 0 0 1 0 0 0
1 1 1 0 1 1 0
1 1 0 1 0 1 0
0 0 0 1 1 0 0
1 0 0 0 0 0 0

NO

YES
0 1 0 0 1 0
1 0 0 1 1 0
0 0 0 0 0 1
0 1 0 0 0 0
1 1 0 0 0 0
0 0 1 0 0 0

#Source

POJ Monthly–2004.05.15 Alcyone@pku

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79


#include <cstring>
#include <algorithm>
using namespace std;

const int maxn=15;
struct {
int id;
int deg;
}v[maxn];
bool (node a,node b)
{
return a.deg>=b.deg;
}
int e[maxn][maxn];大专栏  poj 1659 Frog's Neighborhoodr>
int main()
{
int T;
scanf("%d",&T);
while (T--)
{
int n;
scanf("%d",&n);
for (int i=0;i<n;i++)
{
scanf("%d",&v[i].deg);
v[i].id=i;
}
int flag=1;
memset(e,0,sizeof(e));
for (int k=0;k<n;k++)
{
sort(v+k,v+n,cmp);
int id=v[k].id;
int d1=v[k].deg;
if(d1>n-k-1)
{
flag=0;
continue;
}
for (int mm=1;mm<=v[k].deg;mm++)
{
int j=v[k+mm].id;
if(v[k+mm].deg<=0)
{
flag=0;
break;
}
v[k+mm].deg--;
e[id][j]=e[j][id]=1;
}
}
if(!flag)
{
cout<<"NO"<<endl;


}
else
{
cout<<"YES"<<endl;
for (int i=0;i<n;i++)
{
for (int j=0;j<n;j++)
{
if(j) printf(" ");
printf("%d",e[i][j]);
}
puts("");
}

}
if(T)
puts("");
}
return 0;
}

poj 1659 Frog's Neighborhood的更多相关文章

  1. poj 1659 Frogs&#39; Neighborhood 度序列可图化 贪心

    题意: 对一个无向图给出一个度序列,问他是否可简单图化. 分析: 依据Havel定理,直接贪心就可以. 代码: //poj 1659 //sep9 #include <iostream> ...

  2. POJ 1659 Frogs&#39; Neighborhood(度序列组成)

    意甲冠军  中国 依据Havel-Hakimi定理构图即可咯  先把顶点按度数从大到小排序  可图的话  度数大的顶点与它后面的度数个顶点相连肯定是满足的  出现了-1就说明不可图了 #include ...

  3. poj 1659 Frogs&#39; Neighborhood (度序列)

    Frogs' Neighborhood Time Limit: 5000MS   Memory Limit: 10000K Total Submissions: 7295   Accepted: 31 ...

  4. Frogs‘ Neighborhood(POJ 1659 C/C++)

    poj 1659 Description 未名湖附近共有N个大小湖泊L1, L2, ..., Ln(其中包括未名湖),每个湖泊Li里住着一只青蛙Fi(1 ≤ i ≤ N).如果湖泊Li和Lj之间有水路 ...

  5. poj 1659 Frogs' Neighborhood (DFS)

    http://poj.org/problem?id=1659 Frogs' Neighborhood Time Limit: 5000MS   Memory Limit: 10000K Total S ...

  6. poj 1659 Frogs' Neighborhood (贪心 + 判断度数序列是否可图)

    Frogs' Neighborhood Time Limit: 5000MS   Memory Limit: 10000K Total Submissions: 6076   Accepted: 26 ...

  7. POJ 1659 Frogs' Neighborhood(可图性判定—Havel-Hakimi定理)【超详解】

    Frogs' Neighborhood Time Limit: 5000MS   Memory Limit: 10000K Total Submissions: 9897   Accepted: 41 ...

  8. POJ 1659 Frogs' Neighborhood(Havel-Hakimi定理)

    题目链接: 传送门 Frogs' Neighborhood Time Limit: 5000MS     Memory Limit: 10000K Description 未名湖附近共有N个大小湖泊L ...

  9. Poj 1659.Frogs' Neighborhood 题解

    Description 未名湖附近共有N个大小湖泊L1, L2, ..., Ln(其中包括未名湖),每个湖泊Li里住着一只青蛙Fi(1 ≤ i ≤ N).如果湖泊Li和Lj之间有水路相连,则青蛙Fi和 ...

随机推荐

  1. MLP神经网络 隐含层节点数的设置】如何设置神经网络隐藏层 的神经元个数

    神经网络 隐含层节点数的设置]如何设置神经网络隐藏层 的神经元个数 置顶 2017年10月24日 14:25:07 开心果汁 阅读数:12968    版权声明:本文为博主原创文章,未经博主允许不得转 ...

  2. Maven--部署构件至 Nexus

    日常开发生成的快照版本构件可以直接部署到 Nexus 中策略为 Snapshot 的宿主仓库中,项目正式发布的构件则应该部署到 Nexus 中策略为 Release 的宿主仓库中. <proje ...

  3. 将QT窗口嵌入到WinForm窗口

    要想 windows下抓取Qt进程主界面,并嵌入到自己的程序中显示,需要首先设置qt窗口的windowTitle属性,然后就可以通过 windows api 中的 FindWindow 函数查找到窗口 ...

  4. Java 静态static关键字,main函数,对象的初始化过程,对象调用成员,单例模式的设计,静态代码块(6)

    Java 静态static关键字,静态代码块详情参考:static的使用原理讲解http://www.cnblogs.com/itcqx/p/5519464.html main函数: java Mai ...

  5. Mybatis学习——Mybatis入门程序

    MyBatis入门程序 一.查询用户 1.使用客户编号查询用户 (1).创建一个数据表 USE spring; #创建一个名为t_customer的表 CREATE TABLE t_customer( ...

  6. 同时运行两个版本相同的tomcat

    由于项目需要,代理集群和一个节点都部署在本地,那么就需要有两个tomcat,一个部署集群,一个部署项目,我都用了7.0.34版本的tomcat 当启动代理的tomcat成功时,再启动节点的tomcat ...

  7. PAT Advanced 1052 Linked List Sorting (25) [链表]

    题目 A linked list consists of a series of structures, which are not necessarily adjacent in memory. W ...

  8. Python中的encode和decode

    原文地址:http://www.cnblogs.com/tingyugetc/p/5727383.html 1.Python3中对文本和二进制数据进行了比较清晰的区分,文本总是 unicode ,由  ...

  9. linux上一些常用的命令

    1.时时查看tomcat启动信息,首先切换到tomcat的logs目录下 tail -f catalina.out 2.在tomcat的bin目录下启动无权限,需要赋权 chmod 777 *.sh ...

  10. windows系统安装msi文件总提示2502、2503的错误

    首先: 1.按WIN+R,在运行框中输入“gpedit.msc” 确认:2.打开本地策略组编辑器后依次展开 :“计算机配置”->“管理模板”->“windows组件”->“windo ...