Created
March 20, 2020 13:56
-
-
Save dreamer2q/912d7017782e01fce532406509e511c1 to your computer and use it in GitHub Desktop.
Frogs' Neighborhood
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <string.h> | |
#include <algorithm> | |
/* | |
Frogs' Neighborhood | |
*/ | |
bool cmp(int a, int b) { | |
return a > b; | |
} | |
bool drawable(int *a, int n) { | |
for (int i = 0; i < n; i++) { | |
std::sort(a, a + n, cmp); | |
for (int j = 1; j <= a[0]; j++) { | |
a[j]--; | |
if (a[j] < 0) return false; | |
} | |
a[0] = 0; | |
} | |
return true; | |
} | |
int main() { | |
int cases; | |
scanf("%d", &cases); | |
while (cases--) { | |
int n; | |
scanf("%d", &n); | |
int a[11], b[11]; | |
for (int i = 0; i < n; i++) { | |
int tmp; | |
scanf("%d", &tmp); | |
a[i] = b[i] = tmp; | |
} | |
bool flag = drawable(b, n); | |
if (!flag) { | |
printf("NO\n\n"); | |
continue; | |
} | |
printf("YES\n"); | |
int d[11][11]; | |
memset(d, 0, sizeof(d)); | |
for (int i = 0; i < n; i++) { | |
if (a[i] <= 0) continue; | |
for (int j = i + 1; a[i] > 0 && j < n; j++) { | |
if (a[j] > 0 && a[i] > 0) { | |
a[j]--; | |
a[i]--; | |
d[j][i] = d[i][j] = 1; | |
} | |
} | |
} | |
for (int i = 0; i < n; i++) { | |
for (int j = 0; j < n; j++) { | |
printf("%d ", d[i][j]); | |
} | |
printf("\n"); | |
} | |
if (cases != 0) | |
printf("\n"); | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
没做出来