记录编号 119326 评测结果 AAAAAAAAAAAAAAAAAAAA
题目名称 溶液混合 最终得分 100
用户昵称 GravatarHouJikan 是否通过 通过
代码语言 C++ 运行时间 0.039 s
提交时间 2014-09-11 22:15:50 内存使用 0.31 MiB
显示代码纯文本
#include <iostream>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <list>
#include <vector>
#include <ctime>
#include <iterator>
#include <functional>
#define pritnf printf
#define scafn scanf
#define For(i,j,k) for(int i=(j);i<=(k);(i)++)
using namespace std;
typedef long long LL;
typedef unsigned int Uint; 
const int INF=0x7ffffff;
//==============struct declaration==============
struct medicine
{
  double w,v;
  bool operator <(const medicine &rhs) const
  {
    return w<rhs.w;
  } 
};
//==============var declaration=================
const int MAXN=60;
const double eps=1e-6;
medicine med[MAXN];
int n;
double salt,water,tar;
//==============function declaration============

//==============main code=======================
int main()
{  
  string FileName="mix";//程序名 
  string FloderName="COGS";//文件夹名 
  freopen((FileName+".in").c_str(),"r",stdin);
  freopen((FileName+".out").c_str(),"w",stdout);
#ifdef DEBUG  
  system(("cp C:\\Users\\Administrator\\Desktop\\"+FloderName+"\\standard.cpp C:\\Users\\Administrator\\Desktop\\"+FloderName+"\\submit.txt").c_str());
  clock_t Start_Time=clock();
#endif     
  scanf("%d",&n);
  For(i,1,n)
  {
    scanf("%lf",&med[i].w);
    med[i].w/=100;
  }
  For(i,1,n)
    scanf("%lf",&med[i].v);
  scanf("%lf",&tar);
  tar/=100;
  salt=water=0;
  For(i,1,n)
    salt+=med[i].w*med[i].v,water+=med[i].v;
  sort(med+1,med+n+1);
  if (salt/water<tar)//稀了,从最稀得开始减 
  {
     int pos=0;
     while (salt/water-tar<-eps)
     {
       pos++;
       if (pos==n+1)
       {
         printf("%.5lf\n",0.0);
         return 0;
       }
       salt-=med[pos].v*med[pos].w;
       water-=med[pos].v;
     }
     water+=(salt-tar*water)/(tar-med[pos].w);
     pritnf("%.5lf\n",water);
     return 0;
  }
  else
  {
    int pos=n+1;
     while (salt/water-tar>eps)
     {
       pos--;
       if (pos==0)
       {
         printf("%.5lf\n",0.0);
         return 0;
       }
       salt-=med[pos].v*med[pos].w;
       water-=med[pos].v;
     }
     water+=(salt-tar*water)/(tar-med[pos].w);
     pritnf("%.5lf\n",water);
  }
#ifdef DEBUG  
  clock_t End_Time=clock();
  cout<<endl<<endl<<"Time Used: "<<double(End_Time-Start_Time)/CLOCKS_PER_SEC<<endl;
#endif    
  return 0;
}
//================fuction code====================