HDU 3233

Jiajia downloads a lot, a lot more than you can even imagine. Some say that he starts downloading up to 20,000 files together. If 20,000 files try to share a limited bandwidth then it will be a big hazard and no files will be downloaded properly. That is why, he uses a download manager.

If there are T files to download, the download manger uses the following policy while downloading files:

1. The download manager gives the smaller files higher priority, so it starts downloading the smallest n files at startup. If there is a tie, download manager chooses the one with less bytes remaining (for download). We assume that with at least 50 Mega Bytes/sec of bandwidth, n files can be downloaded simultaneously without any problem.

2. The available bandwidth is equally shared by the all the files that are being downloaded. When a file is completely downloaded its bandwidth is instantaneously given to the next file. If there are no more files left except the files that are being downloaded, this bandwidth is immediately shared equally by all remaining files that are being downloaded.

Given the size and completed percentage of each file, your task is to intelligently simulate the behavior of the download manager to find the total time required to download all the files.

Input

The will be at most 10 test cases. Each case begins with three integers T (1 <= T <= 20000), n (1 <= n <= 2000 and 1 <= n <= T) and B (50 <= B <= 1000). Here B denotes the total bandwidth available to Jiajia (In Megabytes/sec). Please note that the download manager always downloads n files in parallel unless there are less than n files available for download. Each of next T lines contains one non-negative floating-point number S (less than 20,000, containing at most 2 digits after the decimal places) and one integer P (0 <= P <= 100). These two numbers denote a file whose size is S megabyte and which has been downloaded exactly P% already. Also note that although theoretically it is not possible that the size of a file or size of its remaining part is a fraction when expressed in bytes, for simplicity please assume that such thing is possible in this problem. The last test case is followed by T=n=B=0, which should not be processed.

Output

For each case, print the case number and the total time required to download all the files, expressed in hours and rounded to 2 digits after the decimal point. Print a blank line after the output of each test case.

Sample Input

6 3 90
100.00 90
40.40 70
60.30 70
40.40 80
40.40 85
40.40 88
1 1 56
12.34 100
0 0 0

Sample Output

Case 1: 0.66

Case 2: 0.00

给一个下载管理器;这个下载管理器从容量最小的开始下载,每次同时下载的个数不能超过n个;下载的总速度为B,下载完之后立即下载下一个

 在第一个示例中,有6个文件和下载管理器可以同时下载3个文件。最小的文件的大小是40.40字节的但也有

四个文件(2th,4th,5th和6th文件)。所以下载管理器选择6th5th和4th文件下载剩余字节数更少。所有这些

文件得到平等的带宽(30.00 mb /秒)。这三个文件第6个文件最先完成。所以瞬间第二文件开始下载。然后,5th号文件

完成为止。所以下一个更大的文件(3号文件)开始下载。这个过程继续,直到所有文件被下载。

通过样例会发现 所需要的时间正好是按一个一个按速度B下载所需要时间;

同时下载n个但是速度慢(B\n),下载一个速度B;

#include 
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
using namespace std;
const int maxn=20000+10;
typedef long long ll;
struct Load
{
    double s;
    double p;
    bool operator <(const Load &d) const
    {
        if(d.s!=s)
            return s        if(p!=d.p)
            return p    }
};
Load ha[maxn];
int main()
{
    int t,n,b;
    int kase=0;
    while(scanf("%d%d%d",&t,&n,&b)&&(t+n+b))
    {
        double sum=0.00;
        for(int i=0; i        {
            scanf("%lf%lf",&ha[i].s,&ha[i].p);
             sum+=(ha[i].s/b)*(100-ha[i].p)/100;//下载完所需时间*剩余字节所占比例;=下载完剩余字节所需时间;
        }
        printf("Case %d: %.2lf\n\n",++kase,sum);
    }
    return 0;
}


 

 
   

转载于:https://www.cnblogs.com/AC-dream/p/5742165.html

你可能感兴趣的:(HDU 3233)