Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
离散和很多年前数学竞赛学过的可图化判定竟然在这里看到了,不贴代码天理不容啊~#include <cstdio> #include <cstring> #include <algorithm> #include <iostream> using namespace std; bool map[12][12]; struct node { short d; short id; }; inline bool cmp(node a,node b) { return b.d<a.d; } int main() { short T,N,k;bool p=true; for(scanf("%hd",&T);T>0;T--) { scanf("%hd",&N);memset(map,false,sizeof(map));k=N; node * data=new node [N+1]; for(short i=0;i<N;i++){scanf("%hd",&data[i].d);data[i].id=i;} while(N>0) { sort(data,data+N,cmp); if(data[0].d>=N||data[0].d<0) { p=false; break; } for(int i=1;i<=data[0].d;i++) { map[data[0].id][data[i].id]=true; map[data[i].id][data[0].id]=true; data[i].d--; } data=&data[1]; N--; } if(!p) { printf("NO\n"); p=true; } else { printf("YES\n"); for(int i=0;i<k;i++) { for(int j=0;j<k;j++) { cout<<map[i][j]<<" "; } printf("\n"); } } printf("\n"); } return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator