3233 Download Manager //2009 Asia Wuhan Regional Contest Hosted by Wuhan University
来源:互联网 发布:数据漏斗模型 编辑:程序博客网 时间:2024/05/22 06:54
Download Manager
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 94 Accepted Submission(s): 52
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.
6 3 90100.00 9040.40 7060.30 7040.40 8040.40 8540.40 881 1 5612.34 1000 0 0
Case 1: 0.66Case 2: 0.00HintExplanationIn 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.
Statistic | Submit | Discuss | Back
#include<stdio.h>
#include<algorithm>
#include<vector>
using namespace std;
const double eps=1e-3;
struct T
{
double sum;
double bf;
} file[20001];
bool cmp(T a,T b)
{
if(a.sum!=b.sum) return a.sum<b.sum;
else return a.bf>b.bf;
}
bool check(double t)
{
if(t==0) return true;
if(t>0&&t<eps) return true;
if(t<0&&t<-eps) return true;
return false;
}
vector<T> q;
int t,n,b,cas=1;
void solve()
{
double tsum=0;
q.clear();
for(int i=0; i<n; i++) q.push_back(file[i]);
int front=n,top=n;
while(!q.empty())
{
front=top;
int si=q.size();
double speed=b*1.0/si;
double tt=100000000.00;
int jishu=0;
for(int i=0; i<q.size(); i++) //找出在队列中哪一个最早被下载完,不一定是第一个
if((q[i].sum*(100-q[i].bf)*0.01)/speed<tt) tt=(q[i].sum*(100-q[i].bf)*0.01)/speed;
for(vector<T>::iterator it=q.begin(); it!=q.end();)
{
//printf("%lf %lf/n",(it->sum*(100-it->bf)*0.01)/speed,tt);
if(check((it->sum*(100-it->bf)*0.01)/speed-tt)) q.erase(it),jishu++;
else
{
//printf("%lf %lf/n",it->bf,(speed*tt)*100/it->sum);
it->bf=it->bf+(speed*tt)*100/it->sum,it++;
}
}
top+=jishu;
for(int i=front; i<top&&top<=t; i++) q.push_back(file[i]);
tsum+=tt;
}
printf("Case %d: %0.2lf/n",cas++,tsum);
}
int main()
{
while(scanf("%d%d%d",&t,&n,&b)!=EOF)
{
if(t==0&&b==0&&n==0) break;
for(int i=0; i<t; i++) scanf("%lf %lf",&file[i].sum,&file[i].bf);
sort(file,file+t,cmp);
if(t<n) n=t;
solve();
puts("");
}
return 0;
}
- 3233 Download Manager //2009 Asia Wuhan Regional Contest Hosted by Wuhan University
- Box Relations //2009 Asia Wuhan Regional Contest Hosted by Wuhan University 拓扑排序
- 简单题 —— Crossing Rivers —— 2009 Asia Wuhan Regional Contest Hosted by Wuhan University
- 3126 Nova //2009 Asia Wuhan Regional Contest Online //MAXMATCH
- hdu 3123 2009 Asia Wuhan Regional Contest Online
- hdu 3123 GCC (2009 Asia Wuhan Regional Contest Online)
- hdu oj 3127 WHUgirls(2009 Asia Wuhan Regional Contest Online)
- HDU 3126 Nova [2009 Asia Wuhan Regional Contest Online]
- hdu oj 3125 Slash (2009 Asia Wuhan Regional Contest Online)
- 2017 Wuhan University Programming Contest 题解
- hdu 3264 Open-air shopping malls 2009 Asia Ningbo Regional Contest Hosted by NIT
- Baidu Astar Contest 2013-03-23 Regional (Wuhan)
- 2017 Wuhan University Programming Contest --Lost in WHU
- 2017 Wuhan University Programming Contest (Online Round)(补题补题)
- 2017 Wuhan University Programming Contest 现场赛G. Room
- WHU B Color 2017 Wuhan University Programming Contest 一道简单树形dp
- 2017 Wuhan University Programming Contest (Online Round) E. Lost in WHU(矩阵快速幂)
- 2017 Wuhan University Programming Contest (Online Round) D. Events,线段树区间更新+最值查询!
- taglist vim
- open_basedir restriction in effect
- 小毛驴
- 重写了equals,为啥一定要重写hashcode
- perl之开头篇
- 3233 Download Manager //2009 Asia Wuhan Regional Contest Hosted by Wuhan University
- Python学习(一)
- ASP调用域用户验证
- Asp.net上传图片同时生成缩略图和水印图后台代码
- 动态SQL
- 启动多媒体支持 {Fedora 13}
- 从清华大学2010研究生开学典礼说开
- ecshop php函数
- JAVA ireport实例