牛客6—— Combination of Physics and Maths (思维)
题意:
矩形的底面积为最后一行数的和,压力为所有数的和,找一个压力/底面积(即压强)最大的可非连续子矩阵。
思路:
选择单列一定优于选择多列,证明:
所以只需要找到每列的最大即可。
代码:
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4.1,sse4.2,avx,avx2,popcnt,tune=native")
#pragma GCC optimize(2)
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define I_int ll
typedef pair<int,int> PII;
inline ll read()
{
ll x=0,f=1;char ch=getchar();
while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
return x*f;
}
char F[200];
inline void out(I_int x) {
if (x == 0) return (void) (putchar('0'));
I_int tmp = x > 0 ? x : -x;
if (x < 0) putchar('-');
int cnt = 0;
while (tmp > 0) {
F[cnt++] = tmp % 10 + '0';
tmp /= 10;
}
while (cnt > 0) putchar(F[--cnt]);
//cout<<" ";
}
int a[300][300];
int main(){
int T=read();
while(T--){
int n=read(),m=read();
double res=1e-18;
for(int i=1;i<=n;i++)
for(int j=1;j<=m;j++) a[i][j]=read();
for(int j=1;j<=m;j++){
ll sum=0;
for(int i=1;i<=n;i++){
sum+=a[i][j];
res=max(res,1.0*sum/a[i][j]);
}
}
printf("%.8f\n",res);
}
return 0;
}

京公网安备 11010502036488号