NYOJ 545-Metric Matrice【模拟】
来源:互联网 发布:数据库update字段 编辑:程序博客网 时间:2024/06/02 05:22
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 ¹ j ¹ 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 - 样例输入
240 1 2 31 0 1 22 1 0 13 2 1 020 32 0
- 样例输出
03
- 来源
第五届河南省程序设计大赛
解题思路:
直接模拟。
#include<stdio.h>#include<string.h>#include<algorithm>using namespace std;int num[30][30];int main(){int t;scanf("%d",&t);while(t--){int i,j;int n;scanf("%d",&n);for(i=0;i<n;i++){for(j=0;j<n;j++){scanf("%d",&num[i][j]);}}int m=1;for(i=0;i<n;i++){if(num[i][i]!=0){printf("1\n");m=0;break;}}if(m==0)continue;for(i=0;i<n;i++){if(m==0)break;for(j=0;j<n;j++){if(i!=j&&num[i][j]<=0){m=0;printf("2\n");break;}}}if(m==0)continue;for(i=0;i<n;i++){if(m==0)break;for(j=0;j<n;j++){if((i!=j)&&(num[i][j]!=num[j][i])) {printf("3\n");m=0;break;}}}if(m==0){continue;}for(i=0;i<n;i++){if(m==0)break;for(j=0;j<n;j++){if(m==0)break;for(int k=0;k<n;k++){if((i!=j)&&(i!=k)&&(j!=k)&&(num[i][j]+num[j][k]<num[i][k])){printf("4\n");m=0;break;}}}}if(m==0)continue;printf("0\n");}return 0;}
0 0
- NYOJ 545-Metric Matrice【模拟】
- nyoj-545-Metric Matrice
- nyoj 545 Metric Matrice
- NYOJ 545题 Metric Matrice
- nyoj 545 Metric Matrice【矩阵】水题
- 题目545Metric Matrice
- Metric Matrice
- 南阳理工OJ_题目545 Metric Matrice
- 第五届河南省赛 zzulioj 1478: Metric Matrice (模拟)
- NYOJ545-Metric Matrice
- Metric Matrice(nyoj545)
- F Metric Matrice
- 第五届省赛题 Metric Matrice
- nyoj 545 Metric
- 河南省第五届程序设计竞赛--Metric Matrice
- 【第五届河南省程序设计大赛】Metric Matrice
- 第五届程序设计大赛 Metric Matrice
- 河南省第五届程序设计大赛—Metric Matrice
- 利用matlab实现最大连通域的人脸识别
- centos 6.5 用户管理
- list不能使用STL算法sort()
- 八大排序算法之归并排序
- Leetcode_78_Subsets
- NYOJ 545-Metric Matrice【模拟】
- CROC 2016 - Elimination Round D 二分+拓扑序+bfs
- PHP几个基础知识点
- 谈谈Spring中的IOC和AOP概念
- clientY pageY screenY
- Telephony MT SMS/MMS FLOW
- linux 重启tomcat 实现自动化部署的一步
- 《大话设计模式(第1~5章)》读书笔记
- 深度学习之对抗样本问题