标签:style io ar os sp for on cti amp
1,Havel-Hakimi定理主要用来判定一个给定的序列是否是可图的。4,判定过程:(1)按降序排序,进入步骤(2)。(2)将第[2,2+s[1]-1]全部减1,若出现负数则不可图,判定结束。若[2,2+s[1]-1]全部变为0,则可图,判定结束。将s[1]删除,跳至步骤(1)。
#include <algorithm> #include <iostream> #include <cstring> #include <cstdlib> #include <cstdio> #include <queue> #include <cmath> #include <stack> #include <map> #include <ctime> #include <iomanip> #pragma comment(linker, "/STACK:1024000000"); #define EPS (1e-6) #define _LL long long #define ULL unsigned long long #define LL __int64 #define INF 0x3f3f3f3f #define Mod 1000000007 /** I/O Accelerator Interface .. **/ #define g (c=getchar()) #define d isdigit(g) #define p x=x*10+c-'0' #define n x=x*10+'0'-c #define pp l/=10,p #define nn l/=10,n template<class T> inline T& RD(T &x) { char c; while(!d); x=c-'0'; while(d)p; return x; } template<class T> inline T& RDD(T &x) { char c; while(g,c!='-'&&!isdigit(c)); if (c=='-') { x='0'-g; while(d)n; } else { x=c-'0'; while(d)p; } return x; } inline double& RF(double &x) //scanf("%lf", &x); { char c; while(g,c!='-'&&c!='.'&&!isdigit(c)); if(c=='-')if(g=='.') { x=0; double l=1; while(d)nn; x*=l; } else { x='0'-c; while(d)n; if(c=='.') { double l=1; while(d)nn; x*=l; } } else if(c=='.') { x=0; double l=1; while(d)pp; x*=l; } else { x=c-'0'; while(d)p; if(c=='.') { double l=1; while(d)pp; x*=l; } } return x; } #undef nn #undef pp #undef n #undef p #undef d #undef g using namespace std; struct N { int ans,id; }st[20]; int mark[20][20]; bool cmp(N n1,N n2) { return n1.ans > n2.ans; } int Solve() { int n,i,j; scanf("%d",&n); memset(mark,0,sizeof(mark)); for(i = 1;i <= n; ++i) scanf("%d",&st[i].ans),st[i].id = i; for(i = 1;i <= n; ++i) { sort(st+i,st+n+1,cmp); for(j = i+1;j <= n && st[i].ans; ++j) { st[j].ans--; st[i].ans--; mark[st[i].id][st[j].id] = 1; mark[st[j].id][st[i].id] = 1; if(st[j].ans == -1) return puts("NO"),0; } } puts("YES"); for(i = 1;i <= n; ++i) for(j = 1;j <= n; ++j) printf("%d%c",mark[i][j],(j == n ? '\n' : ' ')); return 0; } int main() { int T; scanf("%d",&T); while(T--) { Solve(); if(T) puts(""); } return 0; }
POJ 1659 Frogs' Neighborhood Havel-Hakimi定理判断可图
标签:style io ar os sp for on cti amp
原文地址:http://blog.csdn.net/zmx354/article/details/40893889