2020牛客暑期多校训练营(第六场 )C Combination of Physics and Maths(思维)

地址:https://ac.nowcoder.com/acm/contest/5671/C

题意:

给出n*m的矩阵,求子矩阵的最大压强:压力F为子矩阵所有元素之和,受力面积为子矩阵最后一行的元素之和

子矩阵可以不连续

解析:

给出一个比较极端的情况:

1  100  

1  100

1  1

第一列压强为:3  第二列压强为201

合起来为:101

水平选,只会让结果趋于平均值,所以只需求每一列,每列的每个元素分别做为底即可。

#include<bits/stdc++.h>
#include<iostream>
#include<cstring>
#include<string.h>
#include<cmath>
#include<map>
using namespace std;
typedef long long ll;
const int maxn=2e2+20;
int a[maxn][maxn];
int main()
{
    int t;
    scanf("%d",&t);
    while(t--)
    {
        int n,m;
        scanf("%d%d",&n,&m);
        for(int i=1;i<=n;i++)
            for(int j=1;j<=m;j++)
                scanf("%d",&a[i][j]);
        double sum=0;
        for(int i=1;i<=m;i++)
        {
            int md=0;
            for(int j=1;j<=n;j++)    
            {
                md+=a[j][i];
                sum=max(sum,md*1.0/a[j][i]);
            }
        }    
        printf("%.8lf\n",sum);
    }    
}

猜你喜欢

转载自www.cnblogs.com/liyexin/p/13396302.html