POJ 3836 Peer File sharing System

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.