题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3233
题意:有很多文件要下,但是宽带总量是有限的,只能同时下一部分。下载顺序:先下载较小的文件,如果文件大小相同,先下剩余未下载部分较小的。求下载所需时间。一开始按照题目描述分情况写,结果TLE了,看了看其他人提交的几乎都是错过一次就A了,后来想了想不管下什么,每时刻宽带流量是一定的,每时刻时间又一定,所以每时刻下载的文件量是一定的,不管分不分情况都一样,所以就直接求的,然后按照这个想法写好交了一次就A了。
#include <cstdio>
#include <string>
#include <cstdlib>
#include <cmath>
#include <iostream>
#include <cstring>
#include <set>
#include <queue>
#include <algorithm>
#include <vector>
#include <map>
#include <cctype>
using namespace std ;
typedef long long ll;
const double inf = 0x3f3f3f3f3f3f3f;
const int maxn = 25000;
int vis[maxn];
struct file
{
double total, rest, have_down;
file(){};
file(double total,double rest,double have_down) {};
bool operator<(const file &f) const
{
if(total != f.total) return total < f.total;
return rest < f.rest;
}
}f[maxn];
int main()
{
int t,n,b;
int kase = 0;
while(~scanf("%d%d%d",&t,&n,&b))
{
if(!n && !t && !b) break;
double sum = 0.0;
for(int i = 0; i < t; i++)
{
scanf("%lf%lf",&f[i].total, &f[i].have_down);
if(f[i].have_down < 100.0)
f[i].rest = f[i].total * (1.0 - f[i].have_down * 0.01);
else
f[i].rest = 0;
sum += f[i].rest;
}
printf("Case %d: %.2lf\n\n",++kase, sum / b);
}
return 0;
}