HDU 3233 Download Manager (超级简单的方法)

  • Download Manager

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

__题意:__给T(1-20000)个文件,可同时下载n(1-20000 && n ≤T)个文件,带宽为B(50-1000)M byte/s,给出各个文件的大小S (2-2000,浮点数)Mbyte,完成度P%(P为整数1-100),带宽被n个文件均分,越小的文件下载的优先级越高(也就是先下载小的文件)如果文件大小一样,那么就优先考虑剩余度小的(也就是完成度比较高的),如果T=n=B=0,结束输入,每个输出样例间隔一个空行。
这题特别容易被带进去(反正我是被带进去了),让人第一时间就想到模拟,先排好序然后再算哪个先下好再下下一个,这样直到下载完成为止,做过的人都知道这样是特别复杂的。其实这个题可以看成一个一个下载,因为每个文件下载速度都是均分的,而带宽不变,这个让n=T就很容易理解了,这样我们就可以把所有文件未下载的部分加起来然后除以带宽就可以求出下载时间了
AC代码:

#include 
#include 
using namespace std;

int main()
{
	int n, T, B, cnt = 0;
	while(scanf("%d %d %d", &T, &n, &B) && (n || T || B))
	{
		double S, sum = 0.0;
		int P;
		for(int i = 0; i < T; i++)
		{
			scanf("%lf %d", &S, &P);
			sum += S * (1 - P * 1.0 /100);
		}
		printf("Case %d: %.2lf\n\n", ++cnt, sum / B);
	}
	return 0;
} 

End

你可能感兴趣的:(题解,c++,算法)