zoukankan      html  css  js  c++  java
  • 天梯赛

    题目链接: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 }
  • 相关阅读:
    time模块
    Python进程模块
    Django面试题
    基本命令行语句
    scrapy中的配置与中间件
    JSON编码于解码对应dump于load
    python操作数据库
    Python里的方法
    正则表达式
    Python常用模块
  • 原文地址:https://www.cnblogs.com/littlepear/p/6498902.html
Copyright © 2011-2022 走看看