Metric Matrice
时间限制:
1000 ms | 内存限制:
65535 KB
难度:
1
-
The first line of input gives a single integer, 1 ≤ N ≤ 5, the number of test cases. Then follow, for each test case,
* Line 1: One integer, N, the rows and number of columns, 2 <= N <= 30
* Line 2..N+1: N lines, each with N space-separated integers
(-32000 <=each integer <= 32000).
输出
-
Output for each test case , a single line with a single digit, which is the lowest digit of the possible facts on this list:
* 0: The matrix is a metric
* 1: The matrix is not a metric, it violates rule 1 above
* 2: The matrix is not a metric, it violates rule 2 above
* 3: The matrix is not a metric, it violates rule 3 above
* 4: The matrix is not a metric, it violates rule 4 above
样例输入
-
2 4 0 1 2 3 1 0 1 2 2 1 0 1 3 2 1 0 2 0 3 2 0
样例输出
-
0 3
-
输入
给出几条规定,然后判断是否符合条件,输出不同的指令...
本来很水的一道题,但是因为自己疏忽了一个 return,一直wa.......
最后才发现,也是醉了..............
#include<stdio.h>
#include<string.h>
int x[35][35];
void slove(int n)
{
for(int i=0;i<n;++i)
{
if(x[i][i]!=0)
{
printf("1\n");
return;
}
}
for(int i=0;i<n;++i)
{
for(int j=0;j<n;++j)
{
if(i!=j&&x[i][j]<=0)
{
printf("2\n");
return;
}
}
}
for(int i=0;i<n;++i)
{
for(int j=0;j<n;++j)
{
if(i!=j&&x[i][j]!=x[j][i])
{
printf("3\n");
return;
}
}
}
for(int i=0;i<n;++i)
{
for(int j=0;j<n;++j)
{
for(int k=0;k<n;++k)
{
if(i!=j&&j!=k&&i!=k&&x[i][j]+x[j][k]<x[i][k])
{
printf("4\n");
return ;
}
}
}
}
printf("0\n");
}
int main()
{
int t,n;
scanf("%d",&t);
while(t--)
{
scanf("%d",&n);
for(int i=0;i<n;++i)
{
for(int j=0;j<n;++j)
{
scanf("%d",&x[i][j]);
}
}
slove(n);
}
return 0;
}