这是一个定理题;定理的具体内容见:http://blog.csdn.net/shuangde800/article/details/7857246
我的代码如下:
#include<iostream> #include<cstdio> #include<cstring> #include<algorithm> using namespace std; int cmp(int a,int b) { return a>b; } int main() { int a[11000]; int i,j,n; while(scanf("%d",&n)&&n) { for(i=0;i<n;i++) scanf("%d",&a[i]); sort(a,a+n,cmp); int flag=0,k=0; while(1) { int max1=a[k]; if(max1==0) { flag=1; break; } for(i=k+1;i<k+max1+1;i++) { --a[i]; if(a[i]<0) break; } if(i<k+max1+1) break; k++; sort(a+k,a+n,cmp); } if(flag) printf("Possible\n"); else printf("Not possible\n"); } return 0; }
uva--10720Graph Construction +Havel--Hakimi定理
原文地址:http://blog.csdn.net/acm_lkl/article/details/41492067