Frogs ' Neighborhood
Time Limit: 5000MS |
|
Memory Limit: 10000K |
Total Submissions: 8348 |
|
Accepted: 3538 |
|
Special Judge |
Description
Peiling a total of N size Lakes L1, l2, ..., Ln(which includes peiling), each lake Li has a frog Fi(1≤ i ≤ N). If there is a waterway connection between the lake Li and Lj , the Frog Fi and Fj each other as neighbors. It is now known that the number of neighbors per frog x1, x2, ..., xn, please give a link to each of the two lakes.
Input
The first line is the number of groups of test data T(0≤ t ≤20). Each group of data consists of two rows, the first line is an integer n (2 < N < 10), the second row is n integers,x1, x2,..., xN (0≤ XI ≤ N).
Output
For each set of test data entered, if there is no possible connection, output "no". Otherwise, the output is " YES" and an n-n Matrix represents the neighboring relationship between lakes, that is, if Lake i is connected to Lake J by Waterway, the first row The J number is 1, otherwise 0. Output a space between each of the two numbers. If there is more than one possibility, just give a condition that matches the situation. Output a blank line between two adjacent sets of test data.
Sample Input
Sample Output
Source
POJ monthly--2004.05.15 [email protected]
AC Code
#include <stdio.h> #include <stdlib.h> #include <string.h>struct s{int mark,num;} B[22];int map[22][22];int cmp (const void *a,const void *b) {return (* (struct S *) b). num-(* (struct S *) a). Num; int main () {int t;scanf ("%d", &t), while (t--) {int n;scanf ("%d", &n), Int. i;memset (map,0,sizeof (map)); for (i=0;i <n;i++) {scanf ("%d", &b[i].num); b[i].mark=i;} int K=0;while (k<n) {qsort (b+k,n-k,sizeof (B[k]), CMP), if (b[k].num>n-k-1) break;for (i=1;i<=b[k].num;i++) {b[ K+i].num--;if (b[k+i].num<0) break;map[b[k].mark][b[k+i].mark]=map[b[k+i].mark][b[k].mark]=1;} if (I<=b[k].num) break;k++;} if (k<n) printf ("no\n"), Else{int i,j;printf ("yes\n"), for (i=0;i<n;i++) {for (j=0;j<n;j++) {if (j) printf ("%d", MAP[I][J]); elseprintf ("%d", Map[i][j]);} printf ("\ n");}} if (t) printf ("\ n");}}
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
POJ topic 1659 Frogs ' neighborhood (degrees revert to no map)