POJ-3757: Simple Distributed storage system【简单01分数规划(二分)】

来源:互联网 发布:熊神进淘宝店 编辑:程序博客网 时间:2024/06/06 17:19
Simple Distributed storage system
Time Limit: 1000MS Memory Limit: 65536KTotal Submissions: 2144 Accepted: 392

Description

Jack helps his mentor build a simple distributed storage system. He uses several servers and connects them as the following topology:

This distributed storage system contains a group of backend servers and a master server. The backend servers are different from each other while they store identical data, and all of them are invisible to client. When a client machine needs a file, it sends request to a master server. The master server collects different part of the file from some of backend servers. The strategy of the master is like follows.

Each backend server has its own processing throughput and transmission bandwidth. The master server knows that ith backend server’s throughput is pi (MB/s) and bandwidth is bi (MB/s). As the result, omitted the propagation time, handling size of fi MB data and sending to master machine needs time:

Total time = Processing time + Transmission time = fi / pi + fi / bi

In addition, handling 1 MB data on ith server costs ci. (Including electricity consumption and maintenance cost, etc.) In order to minimize the total cost, the master server should carefully decide which backends should be used and how much load they should process. At the same time, because of some consistency consideration, every time the master should choose exactly K backend servers to extract file, and each of them should take exactly the same time to finish the job.

Your task is to write a scheduling program for the master server. Assuming the size of the file is F MB, and the file can be infinitely divided.

Input

The first line contains two integers N and K (K≤ N ≤ 20000), and a real number F. The master should choose exactly K machines among total N backend servers. The F is the size of the file.

The following N lines describe the details of each backend servers. Each line contains three real numbers, pi, bi and ci, representing the processing throughput, bandwidth and unit cost.

Output

The output file contains only one real number, the minimum cost. The answer is less than 10000000000 and should be rounded to four digits

Sample Input

3 2 21 1 21 1 12 2 10

Sample Output

3.0000

Hint

In the sample case, the master should choose the first two backend machines. Each of them should handle 1 MB part of the file (total is 2 MB) in order to make the finishing time identically (2 second). The total cost is 1*2+1*1 = 3.0000


题意:从n台机器中选出k台,来下载大小为f的一个文件(f为实数),每台机器有p,b,c三个属性,并且每台机器下载东西所用的时间满足式子fi/pi+fi/bi,每1M花费ci。让每台机器工作时间相同,求最小的花费。

01分数规划:http://blog.csdn.net/u013761036/article/details/26666261

对于这道题,ans=Σ(f[i]*c[i])

f[i]/p[i]+f[i]/b[i]=f[i]*(p[i]+b[i])/(p[i]*b[i])=time

得到f[i]=time*(p[i]*b[i])/(p[i]+b[i]),左右两边同时求和,f[i]求和即为文件总大小f,令(p[i]*b[i])/(p[i]+b[i])=v[i],即速度,那么time=f/Σv[i]

ans=Σ(f[i]*c[i])=Σ(f*v[i]*c[i])/Σv[i]

#include<stdio.h>#include<algorithm>#define eps 1e-6using namespace std;const int maxn=20005;int n,k;double f;double p,b;double v[maxn],c[maxn];double x[maxn];int check(double l){    for(int i=0;i<n;i++)        x[i]=v[i]*f*c[i]-v[i]*l;    sort(x,x+n);    double sum=0;    for(int i=0;i<k;i++)        sum+=x[i];    if(sum<=0)        return 1;    return 0;}int main(){    while(scanf("%d%d%lf",&n,&k,&f)!=EOF)    {        for(int i=0;i<n;i++)        {            scanf("%lf%lf%lf",&p,&b,&c[i]);            v[i]=(p*b)/(p+b);        }        double l=0,r=10000000000;        double ans=0;        while(r-l>=eps)        {            double mid=(l+r)/2.0;            if(check(mid))                ans=r=mid;            else l=mid;        }        printf("%.4f\n",ans);    }    return 0;}


0 0