zoukankan      html  css  js  c++  java
  • PAT:1070. Mooncake (25) AC

    #include<stdio.h>
    #include<string.h>
    #include<algorithm>
    using namespace std;
    
    struct moomcake
    {
      double store;      //【cation】这个可能是小数!
      double sumPrice;
      double solePrice;
    }M[1010];
    
    bool cmp(moomcake a,moomcake b)
    {
      return a.solePrice>b.solePrice;
    }
    
    int main()
    {
      memset(M,-1,sizeof(M));
      int n;
      double d;
      scanf("%d%lf",&n,&d);
      for(int i=0 ; i<n ; ++i)
        scanf("%lf",&M[i].store);
      for(int i=0 ; i<n ; ++i)
      {
        scanf("%lf",&M[i].sumPrice);
        M[i].solePrice=M[i].sumPrice/M[i].store;
      }
      sort(M,M+n,cmp);
      double p=0;
      for(int i=0 ; i<n && d>0; ++i)
      {
        if(M[i].store<=d)
        {
          p+=M[i].sumPrice;
          d-=M[i].store;
        }
        else if(M[i].store>d)
        {
          p+=M[i].solePrice*d;
          break;
        }
      }
      printf("%.2f
    ",p);
      return 0;
    }
  • 相关阅读:
    Spring MVC(一)
    Spring-IOC总结
    IT
    Spring基础
    Maven
    Ajax笔记
    数据库和SQL语言
    JDBC
    拦截器
    文件上传
  • 原文地址:https://www.cnblogs.com/Evence/p/4325704.html
Copyright © 2011-2022 走看看