poj 1659
来源:互联网 发布:连接网络将服务器 编辑:程序博客网 时间:2024/04/28 10:03
直接用Havel-Hakimi定理,开始运算结果和样例不一样,琢磨了好久才发现此题是special judge!!!
#include <iostream>#include <cstdio>#include <cstring>#include <algorithm>const int maxn = 11;using namespace std;int mat[maxn][maxn];struct node{ int id; int deg;}pot[maxn];bool Cmp(node x,node y){ return x.deg > y.deg;}bool Havel_Hakimi(int n){ for(int i=0; i<=n-1; ++i){ sort(pot+i,pot+n,Cmp); if(i+pot[i].deg >= n) return false; for(int j=i+1; j<=i+pot[i].deg; ++j){ --pot[j].deg; mat[pot[i].id][pot[j].id] = mat[pot[j].id][pot[i].id] = 1; if(pot[j].deg < 0) return false; } } if(pot[n-1].deg != 0) return false; return true;}int main(){ int T; scanf("%d",&T); while(T--){ int n; bool flag; memset(mat,0,sizeof(mat)); scanf("%d",&n); for(int i= 0; i < n; ++i){ pot[i].id = i + 1; scanf("%d",&pot[i].deg); if(pot[i].deg > n-1) flag = false; } if(Havel_Hakimi(n)&&flag){ printf("YES\n"); for(int i=1; i<=n; ++i){ printf("%d",mat[i][1]); for(int j=2; j<=n; j++) printf(" %d",mat[i][j]); putchar('\n'); } } else printf("NO\n"); if(T) printf("\n"); } return 0;}
- POJ 1659
- poj 1659
- poj 1659
- POJ 1659
- poj 1659
- POJ-1659
- poj--1659
- POJ 1659
- poj 1659
- poj 1659
- POJ 1659 Frogs' Neighborhood
- POJ 1659 Havel 定理
- POJ 1659 Frogs' Neighberhood
- poj 1659 Frogs' Neighborhood
- POJ 1659 Frogs' Neighborhood
- POJ:1659Frogs' Neighborhood
- poj 1659 (havel定理)
- Poj 1659 Frogs' Neighborhood
- Linux基本操作 4----- Linux系统目录架构
- 网络
- 白书的一些题目
- 庞果网---回文字符串
- Qt 编码惯例
- poj 1659
- java 最简易记事本,带详细注释,仅供参考!
- codeforces 187 (div2)题解
- cocos简单的3d渲染
- java中引用数据类型
- “第三方支付”盈利模式
- 表单隐藏域的应用
- HDOJ 1231
- 静态分布内存存储trie树