河南省第五届程序设计竞赛--Metric Matrice

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
样例输入
3
4
0 1 2 3
1 0 1 2
2 1 0 1
3 2 1 0
2
0 3
2 0
3
0 1 4
1 0 1
4 1 0
样例输出
0
3
4
#include <iostream>
#include <algorithm>

using std::endl;
using std::cout;
using std::cin;
using std::sort;

int main()
{
	int K;
	cin >> K;
	//用数组来保存每个规则是否成立
	
	while(K--)
	{
		int flag[5] = {0};
		int n;
		cin >> n;
		int data[30][30];
		for(int i=0; i<n; ++i)
			for(int j=0; j<n; ++j)
			{
				cin >> data[i][j];
			}
		for(int i=0; i<n; ++i)
			for(int j=0; j<n; ++j)
			{
				//如果不满足规则1则flag=1
				if(i==j && data[i][i] != 0)
				{
					flag[1] = 1;
				}
				//检查规则二
				if(i != j && data[i][j] <= 0)
				{
					flag[2] = 2;
				}
				//如果不满足规则三
				if(i !=j && data[i][j] != data[j][i])
				{
					flag[3] = 3;
				}
				if(i != j)
				{
					for(int s=0; s<n; ++s)
					{
						if(s != i && data[i][j] + data[j][s] < data[i][s])
						{
							flag[4] = 4;
						}
					}
				}	
			}
		sort(flag+1, flag+5);
		int cnt;
		for( cnt=1 ; cnt<5; ++cnt)
		{
			if(flag[cnt] > 0)
			{
				cout << flag[cnt] << endl;
				break;
			}
		}
		if(cnt >= 5)
			cout << flag[0] << endl;
	}
	system("pause");
	return 0;
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Docker-compose是一个用于定义和运行多个容应用的工具,而Metricbeat是Elasticsearch家族中的一员,用于收集和发送容和宿主机的系统和服务指标数据。那么docker-compose metricbeat是指使用docker-compose来部署和配置Metricbeat的意思。 使用docker-compose部署Metricbeat可以通过以下步骤完成: 1. 首先,在主机上安装Docker和docker-compose。 2. 创建一个名为docker-compose.yml的文件,并在其中定义Metricbeat的配置。 3. 在docker-compose.yml文件中,指定Metricbeat容的版本和镜像。 4. 在服务节section中,配置Metricbeat需要监的容和主机。可以配置需要监的容名称、标签、网络等信息。 5. 配置Metricbeat的输出目的地,比如将数据发送到Elasticsearch、Logstash或者Kibana等。 6. 根据需要,可以设置其他Metricbeat的参数,例如日志路径、采集指标的时间间隔等。 7. 运行docker-compose up命令,以启动Metricbeat容。 通过上述步骤,我们就可以使用docker-compose来部署和配置Metricbeat了。这样做可以简化配置过程,提高可靠性和可维护性。同时,使用docker-compose还可以方便地扩展配置,添加其他服务和容,以满足具体需求。 总结而言,docker-compose metricbeat 是使用docker-compose来部署和配置Metricbeat,方便快捷地收集和发送容和宿主机的系统和服务指标数据。这样可以帮助我们更好地监和管理我们的容环境。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值