题目链接: C-Combination of Physics and Maths
题意:给出一个二维矩阵,求最大压力,压力为子矩阵之和除子矩阵底层元素之和
For each test case, print the maximum pressure within an absolute or relative error of no more than 108 in one line.
1
3 3
1 3 5
6 8 9
2 7 4
4.50000000
详见注释
#include
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;
}
蒟蒻一只,欢迎指正