牛客多校(2020第六场)C Combination of Physics and Maths(贪心)

题目链接:传送门

题解:

  此题就是一个矩阵的最后一行的数代表底面积,所有数的和为重量,求压强P

  • a/b <= (a+c)/(b+d) <= c/d
  • 所以如果选择子矩阵有很多列,则拆成俩个行数不变得更小子矩阵
  • (也就是竖着切),其中一个肯定是不最坏的情况
  • 所以答案就是寻找单列最大值
 1 /*
 2 a/b <= (a+c)/(b+d) <= c/d
 3 所以如果选择子矩阵有很多列,则拆成俩个行数不变得更小子矩阵
 4 (也就是竖着切),其中一个肯定是不最坏的情况
 5 所以答案就是寻找单列最大值
 6 */
 7 #include<iostream>
 8 #include<cstring>
 9 
10 using namespace std;
11 
12 const int MAX_N = 505;
13 int matrix[MAX_N]; //用来存储当前遍历到的列的值
14 double max_res;
15 int n, m;
16 
17 int main() {
18     ios::sync_with_stdio(false); cin.tie(0);
19     int t;
20     cin >> t;
21     while (t--) {
22         memset(matrix, 0, sizeof(matrix));
23         max_res = 0;
24         cin >> n >> m;
25 
26         for (int i = 1; i <= n; i++) 
27             for (int j = 1; j <= m; j++) {
28                 int  a;
29                 cin >> a;
30                 matrix[j] += a;
31                 max_res = max(max_res, 1.0*matrix[j] / a);
32             }     
33 
34         printf ("%.8lf\n", max_res);
35     }
36     return 0;
37 }
38 
39 /*
40 in
41 
42 1
43 3 3
44 1 3 5
45 6 8 9
46 2 7 4
47 
48 out
49 4.50000000
50 */

猜你喜欢

转载自blog.csdn.net/Mrwei_418/article/details/108068802