2020 牛客多校 第六场 C-Combination of Physics and Maths(思维)

题目链接: C-Combination of Physics and Maths

Description

题意:给出一个二维矩阵,求最大压力,压力为子矩阵之和除子矩阵底层元素之和

在这里插入图片描述

Input

  • There are multiple test cases. The first line of input contains an integer T(T <= 100).
  • indicating the number of test cases. For each test case:
    The first line contains two integers n, m(1 <= n, m <= 200) the number of rows and columns of the matrix, respectively.
  • Each of the next nn lines contains mm integers, specifying the matrix (1 <= ai,j<= 5e4).

Output

For each test case, print the maximum pressure within an absolute or relative error of no more than 108 in one line.

Sample Input

1
3 3
1 3 5
6 8 9
2 7 4

Sample Output

4.50000000

Method

  • 利用性质 设列矩阵A, B,必有 压A <= 压A+B <= 压B 或 压B <= 压A+B <= 压A;
  • 所以其实就转换成求压力最大的列矩阵的压力值,O(m*n) 遍历矩阵即可;

Code

详见注释

#include <bits/stdc++.h>

using namespace std;
#pragma GCC optimize(2)
#define ios std::ios::sync_with_stdio(false);cin.tie(0), cout.tie(0);
#define rtxt freopen("in.txt","r",stdin);freopen("out.txt","w",stdout);
#define ll long long
const int Max = 1e3+3;
const int mod = 1e9+7;

int a[Max][Max], n, m, tmp, T;
double ans=0;

int main()
{
	ios
	
	cin >> T;
	while(T--)
	{
		cin >> n >> m;
		for(int i=1; i<=n; i++)
			for(int j=1; j<=m; j++)
				cin >> a[i][j];
		for(int i=1; i<=m; i++)							//遍历矩阵
		{
			tmp = 0;
			for(int j=1; j<=n; j++)
			{
				tmp += a[j][i];
				ans = max(ans, (double)tmp/a[j][i]);	//求最大值
			}
		}
		printf("%.8lf\n", ans);
		ans = 0;
	}
	return 0;
}

蒟蒻一只,欢迎指正

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值