Frogs' Neighborhood
Time Limit: 5000MS   Memory Limit: 10000K
Total Submissions: 7920   Accepted: 3392   Special Judge

Description

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

Input

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

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
 #include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <iomanip>
using namespace std;
const int INF=0x5fffffff;
const int MS=;
const double EXP=1e-;
struct node
{
int degree;
int id;
bool operator <(const node &b) const
{
return degree>b.degree;
}
}nodes[MS]; int edges[MS][MS]; int main()
{
int i,j,k;
int n,T;
cin>>T;
while(T--)
{
cin>>n;
for(i=;i<n;i++)
{
cin>>nodes[i].degree;
nodes[i].id=i;
}
memset(edges,,sizeof(edges));
int flag=;
for(k=;k<n&&flag;k++)
{
sort(nodes+k,nodes+n);
i=nodes[k].id;
int du=nodes[k].degree;
if(du>n-k-)
flag=;
for(int s=;s<=du&&flag;s++)
{
j=nodes[s+k].id;
if(nodes[s+k].degree<=)
flag=;
nodes[s+k].degree--;
edges[i][j]=edges[j][i]=; }
}
if(flag)
{
cout<<"YES"<<endl;
for(i=;i<n;i++)
{
for(j=;j<n;j++)
{
if(j)
cout<<" ";
cout<<edges[i][j];
}
cout<<endl;
}
}
else
cout<<"NO"<<endl;
if(T)
cout<<endl;
}
return ;
}
												

Frogs' Neighborhood的更多相关文章

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

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

  2. poj 1659 Frogs' Neighborhood (DFS)

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

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

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

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

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

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

    Frogs' Neighborhood Time Limit: 5000MS   Memory Limit: 10000K Total Submissions: 10545   Accepted: 4 ...

  6. POJ1659 Frogs' Neighborhood(青蛙的邻居) Havel-Hakimi定理

    Frogs' Neighborhood Time Limit: 5000MS   Memory Limit: 10000K Total Submissions: 8729   Accepted: 36 ...

  7. poj1659 Frogs' Neighborhood

    Frogs' Neighborhood Time Limit: 5000MS   Memory Limit: 10000K Total Submissions: 10239   Accepted: 4 ...

  8. poj 1659 Frogs' Neighborhood( 青蛙的邻居)

    Frogs' Neighborhood Time Limit: 5000MS   Memory Limit: 10000K Total Submissions: 9639   Accepted: 40 ...

  9. POJ1659 Frogs' Neighborhood(Havel定理)

    给一个无向图的度序列判定是否可图化,并求方案: 可图化的判定:d1+d2+……dn=0(mod 2).关于具体图的构造,我们可以简单地把奇数度的点配对,剩下的全部搞成自环. 可简单图化的判定(Have ...

随机推荐

  1. HDU 2035 人见人爱A^B 分类: ACM 2015-06-22 23:54 9人阅读 评论(0) 收藏

    人见人爱A^B Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Su ...

  2. linux运维工程师

    本人是linux运维工程师,对这方面有点心得,现在我说说要掌握哪方面的工具吧说到工具,在行外可以说是技能,在行内我们一般称为工具,就是运维必须要掌握的工具.我就大概列出这几方面,这样入门就基本没问题了 ...

  3. 学习总结(annotation)

    自定义MyAnnotationTest package com.zhanghaobo.annotation; import java.lang.annotation.ElementType; impo ...

  4. 用SSH连接SSH连接nitrous.io

    CSDN怎么传不上图片... http://user.qzone.qq.com/1756942789/blog/1388662053 1:先下载Bitvise SSH 2:打开 keypair man ...

  5. C#和JavaScript的区别

    Strong and Loose Typing: 强弱比较 // C# var customer = new Customer(); //var is compiler inferred //Java ...

  6. 10.关联(Association)

    关联关系是类与类之间最常用的一种关系,它是一种结构化关系,用于表示一类对象与另一类对象之间有联系.它体现的是两个类.或者类与接口之间语义级别的一种强依赖关系,比如我和我的朋友.这种关系比依赖更强.不存 ...

  7. 【css hack】正是我所找的,帮了大忙啊

    (从已经死了一次又一次终于挂掉的百度空间人工抢救出来的,发表日期2014-03-05) 各个浏览器单独设置属性 IE6:能识别下划线 “_” 和 星号 “*“,不能识别 “!important”    ...

  8. List操作之Select

    本文是写给C#新手,老手就勿看了,讲的实际上就是LINQ,谢谢一楼的提醒. 很多时候,从一个关系表中挑出一个我们需要的元素列表采用SQL语句是再容易不过的了,其实C#的List中也可以采用类似的方法, ...

  9. C#FTP下载文件出现远程服务器返回错误: (500) 语法错误,无法识别命令

    如果下载多个文件的时候,有时候莫名其妙的出现500服务器错误,很有可能是没有设置KeepAlive 属性导致的. 出现应用程序未处理的异常:2015/1/6 11:40:56 异常类型:WebExce ...

  10. The J1850 Core

    http://www.digidescorp.com/wp-content/uploads/2012/02/J1850-Datasheet-pdf.pdf