• 天梯赛


    题目链接:https://www.patest.cn/contests/gplt/L2-003

    现在只能做水题~

     1 #include <iostream>
     2 #include <cstdio>
     3 #include <cstring>
     4 #include <algorithm>
     5 using namespace std;
     6 const int maxn = 1e3+5;
     7 struct _node_
     8 {
     9     double save;
    10     double saleprice;
    11     double costperformance;
    12 };
    13 _node_ node[maxn];
    14 bool cmp(_node_ A,_node_ B)
    15 {
    16     return A.costperformance>B.costperformance;
    17 }
    18 int main()
    19 {
    20     int n;
    21     double maxneed;
    22     cin>>n>>maxneed;
    23     for(int i=0;i<n;i++)
    24     {
    25         cin>>node[i].save;
    26     }
    27     for(int i=0;i<n;i++)
    28     {
    29         cin>>node[i].saleprice;
    30     }
    31     for(int i=0;i<n;i++)
    32     {
    33         node[i].costperformance = node[i].saleprice/node[i].save;
    34     }
    35     sort(node,node+n,cmp);
    36     double sum = 0;
    37     for(int i=0;i<n;i++)
    38     {
    39         if(node[i].save<maxneed)
    40         {
    41             sum += node[i].saleprice;
    42             maxneed -= node[i].save;
    43         }
    44         else if(node[i].save>=maxneed)
    45         {
    46             sum += node[i].costperformance*maxneed;
    47             break;
    48         }
    49     }
    50     printf("%.2f
    ",sum);
    51     return 0;
    52 }
  • 相关阅读:
    CPU运行原理
    ucore代码分析
    ThreadLocal是否会导致内存泄露
    2018 多校联合训练 4
    2018 多校联合训练 3
    2018 牛客多校 4
    2018 牛客多校 3
    2018 牛客多校 2
    2018 牛客多校 1
    2018 多校联合训练 2
  • 原文地址:https://www.cnblogs.com/littlepear/p/6498902.html
Copyright © 2020-2023  润新知