HDU3233 UVA12231 LA4486 Download Manager【模拟】

Download Manager

Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 1563 Accepted Submission(s): 800

Problem Description
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

Hint
Explanation

In the first sample, there are 6 files and the download manager can download 3 files simultaneously. The size of the smallest file is 40.40 Megabyte but there are
four such files (2nd, 4th, 5th and 6th files). So the download manager chooses the 6th, 5th and 4th files for download as they have less bytes remaining. All these
files get equal bandwidth (30.00 Megabyte/Sec). Of these three files the 8th file is finished first. So instantaneously the 2nd file starts downloading. Then, 5th file
is finished. So the next larger file (3rd file) starts downloading. This process goes on until all files are downloaded.

Source
2009 Asia Wuhan Regional Contest Hosted by Wuhan University

问题链接HDU3233 UVA12231 LA4486 Download Manager
问题简述:(略)
问题分析
    模拟下载器下载文件,每次下载从最小的开始,并且每次最多同时下载三个文件,带宽一定,平均分配,求总时间。
    题面的作用就是挖坑,先把人绕晕再说。实际上,因为下载的总量是一定的,下载速度及带宽也是一定的,所以消耗时间不受文件下载的先后顺寻影响。
程序说明
    程序在UVALive中提交出现WA。
参考链接:(略)
题记:(略)

AC的C++语言程序如下:

/* HDU3233 UVA12231 LA4486 Download Manager */

#include <bits/stdc++.h>

using namespace std;

int main()
{
    int t, caseno = 0, n, b;
    while(~scanf("%d%d%d", &t, &n, &b) && (t || n || b)) {
        double s;
        int p;
        double sum = 0;
        for(int i = 1; i <= t; i++) {
            scanf("%lf%d", &s, &p);
            sum += s * (1 - p / 100.00);
        }

        printf("Case %d: %.2f\n\n", ++caseno, sum / b);
    }

    return 0;
}
发布了2126 篇原创文章 · 获赞 2306 · 访问量 254万+

猜你喜欢

转载自blog.csdn.net/tigerisland45/article/details/104468908