【多校联赛】Combination of Physics and Maths

Combination of Physics and Maths

题意:

计算上面的压强

题解:

首先最大值一定是单列,所以直接遍历就可以了

代码:
///Combination of Physics and Maths
#include 
#include 
#include 
#include 
#include 
#include 
using namespace std;
struct pp
{
    double s;
    int num;
}p[205];
double cmp(pp a,pp b)
{
    return a.s>b.s;
}
int main()
{
    long long int t,n,m,i,j,F,S,a[205][205];
    double P;
    scanf("%lld", &t);
    while(t--)
    {
        scanf("%lld%lld",&n, &m);
        F=S=0;
        for(i=0;i<n;i++)
        {
            for(j=0;j<m;j++)
            {
                scanf("%lld", &a[i][j]);
                F+=a[i][j];
                if(i==n-1)
                    S+=a[i][j];
            }
        }
        double ans=0;
        for ( i = 0; i < m; i++){
            double tt = 0;
            for (j = 0; j < n; j++) {
                tt = tt + a[j][i];
                ans = max(ans, tt / a[j][i]);
            }
        }
        printf("%.8lf\n",ans);
    }
    return 0;
}

你可能感兴趣的:(题解)