牛客网多校第4场 D Another Distinct Values 【构造】
生活随笔
收集整理的這篇文章主要介紹了
牛客网多校第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("\n"); 49 } 50 } 51 } View Code?
轉載于:https://www.cnblogs.com/zmin/p/9443455.html
總結
以上是生活随笔為你收集整理的牛客网多校第4场 D Another Distinct Values 【构造】的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 你的微信二维码是唯一的吗?【微信二维码的
- 下一篇: UR #3 核聚变反应强度( gcd )