题目链接:http://poj.org/problem?id=1659

题目:

题意:根据他给你的每个点的度数构造一张无向图。

思路:自己WA了几发(好菜啊……)后看到discuss才知道这个要用Havel-Hakimi定理,就跑去搜,这个定理很好理解,想了解的看官请点击链接:http://blog.51cto.com/sbp810050504/883904。

代码实现如下:

 #include <set>
#include <map>
#include <queue>
#include <stack>
#include <cmath>
#include <bitset>
#include <cstdio>
#include <string>
#include <vector>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std; typedef long long ll;
typedef pair<ll, ll> pll;
typedef pair<ll, int> pli;
typedef pair<int, ll> pil;;
typedef pair<int, int> pii;
typedef unsigned long long ull; #define lson i<<1
#define rson i<<1|1
#define bug printf("*********\n");
#define FIN freopen("D://code//in.txt", "r", stdin);
#define debug(x) cout<<"["<<x<<"]" <<endl;
#define IO ios::sync_with_stdio(false),cin.tie(0); const double eps = 1e-;
const int mod = ;
const int maxn = 1e6 + ;
const double pi = acos(-);
const int inf = 0x3f3f3f3f;
const ll INF = 0x3f3f3f3f3f3f3f; int t, n;
int mp[][]; struct node {
int id, w;
bool operator < (const node& x) const {
return w > x.w;
}
}a[]; int main() {
//FIN;
scanf("%d", &t);
for(int icase = ; icase <= t; icase++) {
if(icase != ) printf("\n");
memset(mp, , sizeof(mp));
scanf("%d", &n);
for(int i = ; i <= n; i++) {
scanf("%d", &a[i].w);
a[i].id = i;
}
int flag = ;
for(int i = ; i <= n; i++) {
sort(a + , a + n + );
for(int j = ; j <= a[].w; j++) {
a[j+].w--;
mp[a[].id][a[j+].id] = mp[a[j+].id][a[].id] = ;
}
a[].w = ;
for(int j = ; j <= n; j++) {
if(a[j].w < ) {
flag = ;
break;
}
}
if(!flag) break;
}
if(!flag) puts("NO");
else {
puts("YES");
for(int i = ; i <= n; i++) {
for(int j = ; j <= n; j++) {
printf("%d%c", mp[i][j], j == n ? '\n' : ' ');
}
}
}
}
return ;
}

Frogs' Neighborhood(POJ1659+Havel-Hakimi定理)的更多相关文章

  1. POJ1659 Frogs' Neighborhood(Havel–Hakimi定理)

    题意 题目链接 \(T\)组数据,给出\(n\)个点的度数,问是否可以构造出一个简单图 Sol Havel–Hakimi定理: 给定一串有限多个非负整数组成的序列,是否存在一个简单图使得其度数列恰为这 ...

  2. POJ1659 Frogs' Neighborhood(Havel定理)

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

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

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

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

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

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

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

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

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

  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: 6076   Accepted: 26 ...

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

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

  10. Frogs' Neighborhood

    Frogs' Neighborhood Time Limit: 5000MS   Memory Limit: 10000K Total Submissions: 7920   Accepted: 33 ...

随机推荐

  1. 3dContactPointAnnotationTool开发日志(十六)

      调了一上午才发现是把下面这个函数: private float DivideTriangle(int []triangle,out int []outTriangle,List<Vector ...

  2. 【Linux】- 开启远程连接

    1.首先看看自己的Ubuntu是不是已经安装或启用了ssh服务,执行 ps -e |grep ssh 我们看到只有ssh-agent 这个是ssh-client客户端服务,如果有sshd,证明你已经装 ...

  3. IIS安装出现“安装程序无法复制文件CONVLOG.EX_”的解决办法

    重新安装了一次IIS,结果就在重新安装的时候,出现安装程序无法复制文件CONVLOG.EX_,上网找了找资料,是因为secedit.sdb 数据库的问题,既然是因为这个文件的问题,那么我们就可以使用w ...

  4. JVM(一)运行机制

    1.启动流程 2.JVM基本结构 PC寄存器 >每个线程拥有一个PC寄存器 >在线程创建时创建 >指向下一条指令的地址 >执行本地方法时,PC的值为undefined 方法区 ...

  5. Delphi中正常窗口的实现

    摘要: 在Delphi的VCL库中,为了使用以及实现的方便,应用对象Application创建了一个用来处理消息响应的隐藏窗口.而正是这个窗口,使得用VCL开发出来的程序存在着与其他窗口不能正常排列平 ...

  6. DELPHI Showmodal 模式窗体

    Showmodal 是个函数, Show 是个过程 1.     Showmodal: 概念 : 当你调用一个窗口用 SHOWMODAL 时 , 当这个窗口显示出来后 , 程序不会继续自己执行 , 而 ...

  7. C#中整型数据类型

    C#中整型数据类型byte是8位的无符号整数,可是它表示的值的范围是0-255才3位啊怎么说是8位啊?谁能帮我解答 全部答案   八位二进制.0000 0000到1111 1111相当于十进制0-25 ...

  8. WPF值转换实例

    WPF绑定功能非常方便,有时候点击某值时在另t一处显示此值的另一表现形式或调用其对应的其它值,用WPF值转换功能会很方便,下面就一LISTBOX和TEXTBLOCK控件,把LISTBOX中的值转换成除 ...

  9. 第三方框架-纯代码布局:Masonry的简单使用

    Masonry是一个对系统NSLayoutConstraint进行封装的第三方自动布局框架,采用链式编程的方式提供给开发者API.系统AutoLayout支持的操作,Masonry都支持,相比系统AP ...

  10. (三)Redis列表List操作

    List全部命令如下: lset key index value # 将列表key下标为index的元素的值设置为value,当 index 参数超出范围,或对一个空列表(key不存在)进行lset时 ...