Frogs' Neighborhood
来源:互联网 发布:网格划分算法 编辑:程序博客网 时间:2024/05/16 00:51
http://poj.org/problem?id=1659
#include <cstdio>#include <cstring>#include <cstdlib>#include <string>#include <map>#include <iostream>#include <stdexcept>#include <cstddef>#include <algorithm>#include <vector>#include <numeric>#include <cctype>#define LL long long#define Endl endl#define INF 0x7fffffff//#define WJusing namespace std;const int maxn=15;int edge[maxn][maxn];struct vertex{int degree;int index;}v[maxn];bool cmp(const vertex& a,const vertex& b){return b.degree<a.degree;}int main(int argc, char *argv[]){#ifdef WJ//freopen("in.txt","r",stdin);freopen("out.txt","w",stdout);#endifint t,n;scanf("%d",&t);while(t--){scanf("%d",&n);for(int i=0;i<n;i++){scanf("%d",&v[i].degree);v[i].index=i;}memset(edge,0,sizeof(edge));int flag=1;for(int k=0;k<n&&flag;k++){sort(v+k,v+n,cmp);int i=v[k].index;int d1=v[k].degree;if(d1>n-k-1){flag=0; break;}for(int r=1;r<=d1&&flag;r++){int j=v[k+r].index;if(v[k+r].degree<=0) flag=0;v[k+r].degree--;edge[i][j]=edge[j][i]=1;}}if(flag){printf("YES\n");for(int p=0;p<n;p++){for(int q=0;q<n;q++){if(q) printf(" ");printf("%d",edge[p][q]);}printf("\n");}}else printf("NO\n");if(t) printf("\n");}return 0;}
0 0
- Frogs' Neighborhood
- POJ 1659 Frogs' Neighborhood
- POJ_1659 Frogs' Neighborhood
- poj 1659 Frogs' Neighborhood
- POJ 1659 Frogs' Neighborhood
- POJ:1659Frogs' Neighborhood
- PKU 1659 Frogs' Neighborhood
- Poj 1659 Frogs' Neighborhood
- poj 1659 Frogs' Neighborhood
- poj1659 - Frogs' Neighborhood
- poj 1659 Frogs' Neighborhood
- Havel定理---Frogs' Neighborhood
- POJ-1659-Frogs' Neighborhood
- poj_1659 Frogs' Neighborhood
- POJ 1658 Frogs' Neighborhood
- POJ 1659 Frogs' Neighborhood
- POJ 1659 Frogs' Neighborhood
- POJ 1659 Frogs' Neighborhood
- 阿凡提种金子
- sql server 实现分页
- 目标检测的图像特征提取之(三)Haar特征
- 用R做数据分析(2)——R包介绍 R语言进阶之4:数据整形(reshape)
- 去除网页格式的空格
- Frogs' Neighborhood
- 错误:WARN util.NativeCodeLoader: Unable to load native-hadoop library for your platform... using built
- 使用Firefox访问ftp并上传下载文件
- Android事件分发机制完全解析,带你从源码的角度彻底理解(上)
- 太阳光的分解方法
- DOS命令大全(经典收藏)
- linux系统安装 Centos6.4举例
- ChartJs自定义tooltipTemplate
- 两链表的第一个公共结点->二叉树两结点的最近共同父结点