NYOJ545-Metric Matrice
来源:互联网 发布:特斯拉知乎 编辑:程序博客网 时间:2024/05/18 10:27
Metric Matrice
时间限制:1000 ms | 内存限制:65535 KB
难度:1
描述
Given as input a square distance matrix, where a[i][j] is the distance between point i and point j, determine if the distance matrix is "a metric" or not.
A distance matrix a[i][j] is a metric if and only if
1. a[i][i] = 0
2, a[i][j]> 0 if i != j
3. a[i][j] = a[j][i]
4. a[i][j] + a[j][k] >= a[i][k] i 1 j 1 k
输入
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
来源
第五届河南省程序设计大赛
#include<stdio.h>#include<string.h>int a[50][50];int main(){ int i,j,k,n,m,max=0,flag; scanf("%d",&n); while(n--) { flag=0; scanf("%d",&m); memset(a,0,sizeof(a)); for(i=0;i<m;i++) for(j=0;j<m;j++) { scanf("%d",&a[i][j]); } for(i=0;i<m;i++) for(j=0;j<m;j++) { if(a[i][i]!=0) flag=1; if(a[i][j]<=0&&i!=j&&flag>2) flag=2; if(a[i][j]!=a[j][i]&&flag>3) flag=3; for(k=0;k<m;k++) { if(i!=j&&j!=k&&i!=k) { if(a[i][j]+a[j][k]<a[i][k]&&flag==0) flag=4; } } } printf("%d\n",flag); } return 0;}
- NYOJ545-Metric Matrice
- Metric Matrice(nyoj545)
- Metric Matrice
- nyoj-545-Metric Matrice
- nyoj 545 Metric Matrice
- 题目545Metric Matrice
- F Metric Matrice
- 第五届省赛题 Metric Matrice
- NYOJ 545题 Metric Matrice
- NYOJ 545-Metric Matrice【模拟】
- 河南省第五届程序设计竞赛--Metric Matrice
- 南阳理工OJ_题目545 Metric Matrice
- 【第五届河南省程序设计大赛】Metric Matrice
- 第五届程序设计大赛 Metric Matrice
- nyoj 545 Metric Matrice【矩阵】水题
- 河南省第五届程序设计大赛—Metric Matrice
- 第五届河南省赛 zzulioj 1478: Metric Matrice (模拟)
- 河南第五届ACM省赛(Metric Matrice)
- 网赚平台Clixsense+网易手机号邮箱短信提醒调查实现轻松网赚
- Java虚拟机(五)
- 相遇不如不遇,相爱不如不爱
- ArrayList的用法
- 对大数的精度处理(4)_两大数相加
- NYOJ545-Metric Matrice
- java基础18
- 【Unity探究】物理碰撞实验
- QOS 总结
- hdu2454Degree Sequence of Graph G
- SEO如何巧妙应对百度
- Oracle Database 11g Release 2 (11.2) Installati
- linux send与recv函数详解
- F3-fatfree小型php框架教程(六)数据库篇