牛客网多校第4场 D Another Distinct Values 【构造】

题目:戳这里

题意,n*n的矩阵,只能填-1,0,1,问能不能使该矩阵的任意行和列的和都不想等。

解题思路:戳这里

可以说是一目了然了

附ac代码:

 1 #include<iostream>
 2 #include<algorithm>
 3 #include<stdio.h>
 4 #include<string.h>
 5 #include<string>
 6 #include <cmath>
 7 using namespace std;
 8 typedef long long ll;
 9 const ll mod = 1e9 + 7;
10 const int maxn = 2e3 + 10;
11 int a[maxn][maxn];
12 int main()
13 {
14     int t;
15     scanf("%d", &t);
16     int n;
17     while(t--)
18     {
19         memset(a, 0, sizeof(a));
20         scanf("%d", &n);
21         if(n & 1)
22         {
23             puts("impossible");
24             continue;
25         }
26         puts("possible");
27         for(int i = 1; i <= n / 2; ++i)
28         {
29             for(int j = 1; j <= n - i + 1; ++j)
30             {
31                 a[i][j] = 1;
32             }
33         }
34         for(int i = n / 2 + 1; i <= n; ++i)
35         {
36             for(int j = n; j > n - i + 1; --j)
37             {
38                 a[i][j] = -1;
39             }
40         }
41         for(int i = 1; i <= n; ++i)
42         {
43             for(int j = 1; j <= n; ++j)
44             {
45                 if(j > 1) printf(" ");
46                 printf("%d", a[i][j]);
47             }
48             printf("
");
49         }
50     }
51 }
View Code
原文地址:https://www.cnblogs.com/zmin/p/9443455.html