This is a topic of analog-to-peer network. Test instructions is more cumbersome, as long as you understand the class, careful is very good AC. Directly on the code, save the simulation.
#include <stdio.h> #include <string.h> #include <iostream> #include <string> #include <queue > #include <cmath> #include <map> #include <algorithm> #include <vector> #include <bitset >using namespace Std;const int inf = 0x3fffffff;const int mmax = 1010;bool Server[30];bool online[30][mmax];int Speed[3 0][30];int start_time[30];int large[30];int n,t,k,s;void Download (int nowtime, int c_id) {int sum=0; for (int i=1;i<=n;i++) {if (Server[i] && Online[i][nowtime]) {sum+=speed[i][c_id]; }} large[c_id]+=sum;} int main () {int case; scanf ("%d", &case); while (case--) {scanf ("%d%d", &n,&t); scanf ("%d%d", &k,&s); memset (server,0,sizeof Server); memset (online,0,sizeof Online); for (int i=0;i<k;i++) {int x; scanf ("%d", &x); Server[x]=1; } for (int i=1;i<=n;i++) for (iNT j=1;j<=n;j++) {scanf ("%d", &speed[i][j]); if (i==j) speed[i][j]=0; } int t; for (int i=1;i<=n;i++) {scanf ("%d", &t); while (t--) {int st,en; scanf ("%d%d", &st,&en); En=min (en,t+1); for (int j=st+1;j<=en;j++) online[i][j]=1; }} for (int i=1;i<=n;i++) Start_time[i]=inf; cout<<start_time[1]<<endl; int m; scanf ("%d", &m); while (m--) {int download_time,computer_id; scanf ("%d%d", &download_time,&computer_id); Start_time[computer_id]=min (Start_time[computer_id],download_time); } memset (large,0,sizeof Large); for (int i=1;i<=t;i++) {for (int j=1;j<=n;j++) {if (! SERVER[J]&& start_time[j]<i && online[j][i]) Download (I,J); } for (int j=1;j<=n;j++) {if (large[j]>=s) {S Erver[j]=1; Large[j]=s; }}}//for (int i=1;i<=n;i++)//{//cout<<large[i]<< "";// }//cout<<endl; for (int i=1;i<=n;i++) {if (Server[i]) printf ("100%%\n"); else printf ("%d%%\n", large[i]*100/s); }} return 0;}
POJ 3836 Peer File sharing System