Skip to content

Instantly share code, notes, and snippets.

@dreamer2q
Created March 20, 2020 13:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dreamer2q/912d7017782e01fce532406509e511c1 to your computer and use it in GitHub Desktop.
Save dreamer2q/912d7017782e01fce532406509e511c1 to your computer and use it in GitHub Desktop.
Frogs' Neighborhood
#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;
}
@dreamer2q
Copy link
Author

没做出来

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment