Download Manager (HDU3233,UVA12231,UVALive4486) 解题报告

来源:互联网 发布:linux 压缩文件夹 命令 编辑:程序博客网 时间:2024/05/22 00:30

题意:

用一个下载器下载T个文件,同时最多下载n个文件,最大带宽为b(b兆每秒),遵循下面的下载规则,问下载的总耗时

下载规则:

1.文件越小,越优先下载,大小相同的情况下优先下载已完成百分比更大的文件

2.带宽全开,尽可能多的同时下载多个文件(同时最多下载n个文件),带宽平均分布,此时网速为(b/n),当剩余文件小于n时,带宽平均分布到剩余未下载的文件(b/剩余文件数)

输入:

T n B    //T为待下载的文件数,n为最多同时下载的文件数,b为带宽(b兆每秒)

s1 p1    //给出T组数据,s表示每个文件总大小,p表示当前已经下载的百分比(p%)

s2 p2

.

.

st pt

输出:

下载完所有文件的总耗时。(每个case后一个空行)


思路:一开始会想模拟啊,结构体啊,排序啊,下载啊,下载啊,下载啊。。。此处省略很多字

但是一想,网速不是全开吗,就是在每时每刻都是按照b兆每秒来下载的,只要在算出需要下载的文件大小总和,除以b不就OK了?

(n就是打酱油的)

代码:

#include <iostream>#include<cstdio>#include<cmath>#include<algorithm>using namespace std;int main(){    //freopen("in.txt","r",stdin);    int t,n;    double b;    int cnt=1;    while( scanf("%d%d%lf",&t,&n,&b)&&(t||n||b))    {        double sumfile=0;        for (int i=0; i<t; i++)        {            double s,p;            scanf("%lf%lf",&s,&p);            sumfile+=0.01*(s*(100.0-p)); /*计算需要下载的文件总和;                                         但是我不知道这里写成                                         sumfile+=(s*(1-p*0.01));                                         为什么第二个测试用例的答案就变成 -0.00 了,                                         输出用if也处理不掉这个负号                                         有明白的麻烦在评论区给指点一下 */        }        double sumtime;        sumtime=sumfile/b;        printf("Case %d: %.2lf\n\n",cnt++,sumtime);  //此处case从1开始计,而不是0    }    return 0;}

题目:

Download Manager

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 Bdenotes 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 90100.00 9040.40 7060.30 7040.40 8040.40 8540.40 881 1 5612.34 1000 0 0
 

Sample Output
Case 1: 0.66Case 2: 0.00
Hint
ExplanationIn 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.

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3233

参考链接:http://www.acmerblog.com/hdu-3233-download-manager-5101.html


0 0