第五届省赛题 Metric Matrice
来源:互联网 发布:多开同步器软件 编辑:程序博客网 时间:2024/06/05 16:55
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 - 样例输入
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
题意:
题解:这道题是说:给出一个矩阵,看是否是符合规则的。如果均满足下列四种规则,输出0.
如果不满足1输出1
如果不满足2输出2
如果不满足3输出3
如果不满足4输出4
#include<stdio.h>#include<iostream>#include<string.h>#include<algorithm>using namespace std;int map[35][35];int n;int f1(){ int a1=1; for(int i=1;i<=n;i++) { if(map[i][i]!=0) { a1=0; return a1; } } return a1;}int f2(){ int a2=1; for(int i=1;i<=n;i++) { for(int j=1;j<=n;j++) { if(i!=j) if(map[i][j]<=0) { a2=0; return a2; } } } return a2;}int f3(){ int a3=1; for(int i=1;i<=n;i++) for(int j=1;j<=n;j++) { if(map[i][j]!=map[j][i]) { a3=0; return a3; } } return a3;}int f4(){ int a4=1; for(int i=1;i<=n;i++) for(int j=1;j<=n;j++) for(int k=1;k<=n;k++) { if(i!=j&&i!=k&&j!=k) { if(map[i][j]+map[j][k]<map[i][k]) { a4=0; return a4; } } } return a4;}int main(){ int t; scanf("%d",&t); while(t--) { int i,j; scanf("%d",&n); for(i=1;i<=n;i++) for(j=1;j<=n;j++) { scanf("%d",&map[i][j]); } int a1=f1(); int a2=f2(); int a3=f3(); int a4=f4(); if(a1==1&&a2==1&&a3==1&&a4==1) printf("0\n"); else if(a1==0) printf("1\n"); else if(a2==0) printf("2\n"); else if(a3==0) printf("3\n"); else if(a4==0) printf("4\n"); } return 0;}
0 0
- 第五届省赛题 Metric Matrice
- 河南省第五届程序设计竞赛--Metric Matrice
- 【第五届河南省程序设计大赛】Metric Matrice
- 第五届程序设计大赛 Metric Matrice
- Metric Matrice
- 河南省第五届程序设计大赛—Metric Matrice
- 第五届河南省赛 zzulioj 1478: Metric Matrice (模拟)
- 河南第五届ACM省赛(Metric Matrice)
- 郑轻 1478 Metric Matrice (第五届河南省赛)
- nyoj-545-Metric Matrice
- NYOJ545-Metric Matrice
- Metric Matrice(nyoj545)
- nyoj 545 Metric Matrice
- 题目545Metric Matrice
- F Metric Matrice
- NYOJ 545题 Metric Matrice
- NYOJ 545-Metric Matrice【模拟】
- 南阳理工OJ_题目545 Metric Matrice
- 微服务架构Spring Cloud和Dubbo 还有EDAS
- Activity跳转、子线程
- 【Android】二维码识别性能优化
- Linux 用户权限设置和切换用户
- PHP7 操作MongoDB
- 第五届省赛题 Metric Matrice
- Bmob实现登陆注册,解决官方signUp与Success方法更新后出错问题
- Integer和int的种种比较
- 范数
- 算法/排序算法/RandomQuickSort随机快速排序
- Android官方提供的支持不同屏幕大小的全部方法
- css字体大小设置em与rem的区别
- 数据库实践三:再也不想经历的配环境体验
- Linux学习第五单元-使用逻辑卷管理器管理灵活存储