首页 > 其他 > 详细

PAT:1070. Mooncake (25) AC

时间:2015-03-10 13:50:24      阅读:179      评论:0      收藏:0      [点我收藏+]
#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\n",p);
  return 0;
}

PAT:1070. Mooncake (25) AC

原文:http://www.cnblogs.com/Evence/p/4325704.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!