procedure2012
It's not worth it to know you're not worth it!

[关键字]:模拟

[题目大意]:模拟一个P2P 下载,每对机器都有一个传输速率,每一个机器都有在线和离线时间,和下载的开始时间,当一个机器开始下载时,它将从所有在线且提供下载且与他有速度的服务器上下载。当它下载完成时,下一秒它就变成了服务器。问T时间之后,各个机器的完成百分比是多少。

//=====================================================================================

[分析]:枚举每一秒直接模拟这一秒有那些电脑可以下载并枚举那些服务器可以下载,然后更新下载量。如果以下载完就把他标记成服务器。

[代码]:

View Code
#include<iostream>
#include<cstdlib>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;

int n,m,K,S,T;
int serve[21],speed[21][21];
int online[21][11][2],start[21];
int sum[21],temp[21];

void Init()
{
int x,y;
scanf("%d%d",&n,&T);
scanf("%d%d",&K,&S);
for (int i=1;i<=K;++i) scanf("%d",&serve[i]),sum[serve[i]]=S;
for (int i=1;i<=n;++i)
for (int j=1;j<=n;++j)
scanf("%d",&speed[i][j]);
for (int i=1;i<=n;++i)
{
scanf("%d",&online[i][0][0]);
for (int j=1;j<=online[i][0][0];++j) scanf("%d%d",&online[i][j][0],&online[i][j][1]);
}
scanf("%d",&m);
for (int i=1;i<=m;++i)
{
scanf("%d%d",&x,&y);
if (start[y]==-1 || start[y]>x) start[y]=x;
}
//printf("%d %d %d %d\n",n,T,K,S);
}

bool Judge(int x,int y)
{
for (int i=1;i<=online[x][0][0];++i)
if (online[x][i][0]<=y && y<online[x][i][1]) return 1;
return 0;
}

bool Cleck(int x,int y)
{
for (int i=1;i<=K;++i)
if (serve[i]==x) return 0;
if (start[x]>y || start[x]==-1) return 0;
if (Judge(x,y)) return 1; else return 0;
}

void Solve()
{
int tmp;
for (int i=0;i<T;++i)
{
tmp=0;
for (int j=1;j<=n;++j)
if (Cleck(j,i))
{
for (int k=1;k<=K;++k)
if (Judge(serve[k],i))
sum[j]+=speed[serve[k]][j];
if (sum[j]>=S) temp[++tmp]=j;
//printf("%d %d %d\n",i,j,sum[j]);
}
for (int j=1;j<=tmp;++j) serve[++K]=temp[j];
}
//for (int i=1;i<=n;++i) printf("%d\n",sum[i]);
for (int i=1;i<=n;++i)
if (sum[i]>=S)
printf("100%%\n");
else
printf("%d%%\n",(sum[i]*100)/S);
}

void Prepare()
{
memset(serve,0,sizeof(serve));
memset(online,0,sizeof(online));
memset(sum,0,sizeof(sum));
memset(speed,0,sizeof(speed));
memset(start,255,sizeof(start));
}

int main()
{
freopen("in.txt","r",stdin);
freopen("out.txt","w",stdout);
int test;
scanf("%d",&test);
while (test--)
{
Prepare();
Init();
Solve();
}
return 0;
}



posted on 2012-03-15 20:47  procedure2012  阅读(184)  评论(0编辑  收藏  举报