1730: Tractatus Logico-Philosophicus
Time Limit: 1 Sec
Memory Limit: 128 MB
Special Judge
Submit: 45
Solved: 26
[ Submit][ Status][ Web Board]
Description
This book is written by Ludwig Josef Johann Wittgenstein;
There are seven main propositions in the text. These are:
-
The world is everything that is the case.
-
What is the case (a fact) is the existence of states of affairs.
-
A logical picture of facts is a thought.
-
A thought is a proposition with a sense.
-
A proposition is a truth-function of elementary propositions. (An elementary proposition is a truth-function of itself.)
-
The general form of a proposition is the general form of a truth function, which is:
. This is the general form of a proposition.
-
Whereof one cannot speak, thereof one must be silent.
Wittgenstein deduced our world was made up of logical word or logical picture.
There was a Conclution found by Wittgenstein that The most experienced Gods have to find a magic matrix of the size n × n (n is even number) to make our world .Matrix should contain integers from 0 to n - 1, main diagonal should contain only zeroes and matrix should be symmetric. Moreover, all numbers in each row and cloumn should be different. You found this secret after reading <<Tractatus Logico-Philosophicus>>.So output the world.
Input
The first line contains one integer T(1≤ T ≤ 10), There are T cases;
The next T lines contains one integer n( 2≤ n ≤ 1000) , n is even number.
Output
Output n lines with n numbers each for each case— the required matrix. Separate numbers with spaces. If there are several solutions, output any.
Sample Input
2
2
4
Sample Output
0 1
1 0
0 1 3 2
1 0 2 3
3 2 0 1
2 3 1 0
HINT
Source
题意:构造一个n*n的矩阵,使得每行每列没有重复的元素
题解:其实是非常简单的一个构造呀!只要胆大敢交就能AC,观察一下样例就可以找打一些规律,对角线的数字相同,然后矩阵的第一行的数字为0。。。。。n-1,然后按照规则构造就可以了,原本比赛1个多小时就敲好了,输入6,发现无法得到符合题意的矩阵,我不信,就把6的全排列跑了一边,还是不行,于是就没有交了,但是队友说6确实构造不出来,你尝试交一下,让后就AC了。。。。。。。。我也不知道原理。。迷之AC
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<cmath>
#include<iostream>
#include<algorithm>
#include<vector>
#include<map>
#include<set>
#include<queue>
#include<string>
#include<bitset>
#include<utility>
#include<functional>
#include<iomanip>
#include<sstream>
#include<ctime>
using namespace std;
#define N int(2e3+10)
#define inf int(0x3f3f3f3f)
#define mod int(1e9+7)
typedef long long LL;
#ifdef CDZSC
#define debug(...) fprintf(stderr, __VA_ARGS__)
#else
#define debug(...)
#endif
int g[N][N];
int main()
{
#ifdef CDZSC
freopen("i.txt", "r", stdin);
//freopen("o.txt","w",stdout);
int _time_jc = clock();
#endif
int t,n;
scanf("%d",&t);
while(t--)
{
scanf("%d",&n);
for(int i=1;i<n;i++)
{
g[i][0]=i;
g[i][n-1]=n-i-1;
}
for(int i=1;i<n;i++)
{
int k=i;
int p=0;
while(k>0)
{
g[k-1][p+1]=g[k][p];
k-=1;
p+=1;
}
}
for(int i=n-1;i>=1;i--)
{
int k=i;
int p=n-1;
while(k<n)
{
g[k+1][p-1]=g[k][p];
k+=1;
p-=1;
}
}
for(int i=0;i<n;i++)
g[i][i]=0;
for(int i=0;i<n;i++)
{
for(int j=0;j<n;j++)
{
if(j)printf(" ");
printf("%d",g[i][j]);
}
printf("\n");
}
}
#ifdef CDZSC
debug("time: %d\n", int(clock() - _time_jc));
#endif
return 0;
}
1730: Tractatus Logico-Philosophicus
Time Limit: 1 Sec
Memory Limit: 128 MB
Special Judge
Submit: 45
Solved: 26
[ Submit][ Status][ Web Board]
Description
This book is written by Ludwig Josef Johann Wittgenstein;
There are seven main propositions in the text. These are:
-
The world is everything that is the case.
-
What is the case (a fact) is the existence of states of affairs.
-
A logical picture of facts is a thought.
-
A thought is a proposition with a sense.
-
A proposition is a truth-function of elementary propositions. (An elementary proposition is a truth-function of itself.)
-
The general form of a proposition is the general form of a truth function, which is:
. This is the general form of a proposition.
-
Whereof one cannot speak, thereof one must be silent.
Wittgenstein deduced our world was made up of logical word or logical picture.
There was a Conclution found by Wittgenstein that The most experienced Gods have to find a magic matrix of the size n × n (n is even number) to make our world .Matrix should contain integers from 0 to n - 1, main diagonal should contain only zeroes and matrix should be symmetric. Moreover, all numbers in each row and cloumn should be different. You found this secret after reading <<Tractatus Logico-Philosophicus>>.So output the world.
Input
The first line contains one integer T(1≤ T ≤ 10), There are T cases;
The next T lines contains one integer n( 2≤ n ≤ 1000) , n is even number.
Output
Output n lines with n numbers each for each case— the required matrix. Separate numbers with spaces. If there are several solutions, output any.
Sample Input
2
2
4
Sample Output
0 1
1 0
0 1 3 2
1 0 2 3
3 2 0 1
2 3 1 0
HINT
Source