题目链接: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. bwapp之xss(blog)

    存储型XSS,持久化,代码是存储在服务器中的,如在个人信息或发表文章等地方,加入代码,如果没有过滤或过滤不严,那么这些代码将储存到服务器中,用户访问该页面的时候触发代码执行.这种XSS比较危险,容易造 ...

  2. (转)《linux性能及调优指南》 3.3 内存瓶颈

    翻译:Hank (http://blog.csdn.net/fireroll)版权所有,尊重他人劳动成果,转载时请注明作者和原始出处及本声明.原文名称:<Linux Performance an ...

  3. TCP标志位简析

    TCP标志位简析   TCP标志位  URG:此标志表示TCP包的紧急指针域(后面马上就要说到)有效,用来保证TCP连接不被中断,并且督促中间层设备要尽快处理这些数据: ACK:此标志表示应答域有效, ...

  4. [OS] 多线程--第一次亲密接触CreateThread与_beginthreadex本质区别

    转自:http://blog.csdn.net/morewindows/article/details/7421759 本文将带领你与多线程作第一次亲密接触,并深入分析CreateThread与_be ...

  5. 【Python】Python中的引用和赋值

    本文转自:http://my.oschina.net/leejun2005/blog/145911 在 python 中赋值语句总是建立对象的引用值,而不是复制对象.因此,python 变量更像是指针 ...

  6. jQuery实现三级联动

    <!DOCTYPE html> <html> <head> <meta http-equiv="Content-Type" content ...

  7. Axure RP 的安装与卸载

    官网:http://www.axure.com/download 支持Windows和Mac

  8. 为windows phone listbox 添加触摸倾斜效果

    在开发windows phone程序时,经常会用到listbox或者是longlistselector等列表控件.当点击时没有触摸效果体验会稍差一些,像windows phone中的设置页面一样,点击 ...

  9. Codeforces Round #521 Div. 3 玩耍记

    A:签到. #include<iostream> #include<cstdio> #include<cmath> #include<cstdlib> ...

  10. 【SPOJ - GSS2】Can you answer these queries II(线段树)

    区间连续不重复子段最大值,要维护历史的最大值和当前的最大值,打两个lazy,离线 #include<cstdio> #include<cstring> #include< ...