POJ topic 1659 Frogs ' neighborhood (degrees revert to no map)

Source: Internet
Author: User

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≤ iN). 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)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.