意甲冠军  中国

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

#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
const int N = 20;
int mat[N][N], ord[N]; bool cmp(int i, int j)
{
return mat[i][0] > mat[j][0];
} int main()
{
int cas, i, j, k, t, n;
scanf("%d", &cas);
while(cas--)
{ memset(mat, 0, sizeof(mat));
scanf("%d", &n);
for(i = 1; i <= n; ++i)
{
scanf("%d", &mat[i][0]);
ord[i] = i;
} for(i = 1; i <= n; ++i)
{
sort(ord + i, ord + n + 1, cmp);
t = ord[i];
if(mat[t][0] < 0) break;
for(j = 1; j <= mat[t][0]; ++j)
{
k = ord[i + j];
mat[t][k] = mat[k][t] = 1;
--mat[k][0];
}
} if(i <= n) printf("NO\n");
else
{
printf("YES\n");
for(i = 1; i <= n; ++i)
{
for(int j = 1; j <= n; ++j)
printf("%d ", mat[i][j]);
printf("\n");
}
}
if(cas) printf("\n");
}
return 0;
}

Frogs' Neighborhood

Description

未名湖附近共同拥有N个大小湖泊L1L2, ..., Ln(当中包含未名湖)。每一个湖泊Li里住着一仅仅青蛙Fi(1 ≤ i ≤ N)。假设湖泊LiLj之间有水路相连,则青蛙FiFj互称为邻居。如今已知每仅仅青蛙的邻居数目x1x2,
..., xn。请你给出每两个湖泊之间的相连关系。

Input

第一行是測试数据的组数T(0 ≤ T ≤ 20)。

每组数据包含两行。第一行是整数N(2 < N < 10),第二行是N个整数。x1x2,..., 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 1659 Frogs&#39; Neighborhood(度序列组成)的更多相关文章

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

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

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

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

  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 Description 未名湖附近共有N个大小湖泊L ...

  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 Havel-Hakimi定理 可简单图定理

    作者:jostree 转载请注明出处 http://www.cnblogs.com/jostree/p/4098136.html 给定一个非负整数序列$D=\{d_1,d_2,...d_n\}$,若存 ...

  7. poj 1659 Frog's Neighborhood

    未名湖附近共有N个大小湖泊L1, L2, -, Ln(其中包括未名湖),每个湖泊Li里住着一只青蛙Fi(1 ≤ i ≤ N).如果湖泊Li和Lj之间有水路相连,则青蛙Fi和Fj互称为邻居.现在已知每只 ...

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

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

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

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

随机推荐

  1. C++基础知识---static const初始化成员变量

    为了限制常数的范围class中.你必须要做出成为class成员:而要确保这是丝毫不亚于有一个恒定的实体.你必须要做出成为static员: Class Gameplayer { Private: Sta ...

  2. HDU4344(大数分解)

    题目:Mark the Rope 题意就是给一个数,然后求这个数的所有因子中组成的最大的一个子集,其中1和本身除外,使得在这个子集中元素两两互素,求最大子集的元素个 数,并且求出和最大的值. 找规律就 ...

  3. SE 2014年4月2日

    一 描述OSPF协议 LSA(Type 1~5)的名称,始发者以及特点 第一类LSA (router lsa)该类lSA为启动了ospf进程的所有路由器都可以产生,该类LSA主要含有本地路由器的接口状 ...

  4. hotmail邮箱pop3server设置方法

    hotmail邮箱 的POP3/SMTP功能仅仅向Hotmail Plus的用户开放,普通用户想要使用这一功能的话,得进行一些特别的设置.如今这一功能总算面向全部的用户开放了,虽然微软官方还没宣布这一 ...

  5. SWT的CheckBoxTreeView的上级菜单与下级菜单的选中的实现

    是不是很神奇? treeViewer.addCheckStateListener(new ICheckStateListener() { @Override public void checkStat ...

  6. CSharp Oracle 登陆

    =======后台Oracle存储过程================ 1.创建表 --判读表存在先删除begin    EXECUTE IMMEDIATE 'DROP TABLE student'; ...

  7. shell统计

    for i in `ls -r *_*.csv`;do cat $i|echo $i": "`wc -l`;done>tongji.txt

  8. angularjs入门学习【指令篇】

    一.首先我们来了解下指令API 属性 含义 restrict 申明标识符在模版中作为元素,属性,类,凝视或组合,怎样使用 priority 设置模版中相对于其它标识符的运行顺序 Template 指定 ...

  9. 解决错误 fatal error C1010: unexpected end of file while looking for precompiled head

    在编译VS时候,出现fatal error C1010: unexpected end of file while looking for precompiled head. 问题详解:致命错误C10 ...

  10. 阐述php(四) 流量控制

    一个.选择结构 1. 单路分支 <? php if(条件){ 运行一条语句; } ?> 2. 双路分支 <?php if(条件) 运行一条语句; }else 运行一条语句; } ?& ...