zoukankan      html  css  js  c++  java
  • 牛客多校(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
    ", 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 */
  • 相关阅读:
    codeforces 407B Long Path
    CodeForces 489C Given Length and Sum of Digits...
    hacker cup 2015 Round 1 解题报告
    hacker cup 2015 资格赛
    Codeforces 486(#277 Div 2) 解题报告
    POJ 3468 A Simple Problem with Integers splay
    Codeforces 484(#276 Div 1) D Kindergarten DP
    求平均值问题201308031210.txt
    I love this game201308022009.txt
    QQ
  • 原文地址:https://www.cnblogs.com/mr-wei977955490/p/15367573.html
Copyright © 2011-2022 走看看