HDU 3269 P2P File Sharing System 模拟

来源:互联网 发布:cmd网络修复命令 编辑:程序博客网 时间:2024/05/21 09:05

                                                                                                     P2P File Sharing SystemCrawling in process...

Crawling failed                                                                     Time Limit:1000MS    Memory Limit:65536KB     64bit IO Format:%lld & %llu   

Description

Input

Output

Sample Input

Sample Output

Hint

Description

Peer-to-peer(P2P) computing technology has been widely used on the Internet to exchange data. A lot of P2P file sharing systems exist and gain much popularity in nowadays.

Let's consider a simplified model of P2P file sharing system: There are many computers in the system, and they can receive data from or send data to others. To simplify the problem, let's assume that there is just ONE large file which is of our concern in the system. Some computers already have the whole file (we call them "servers") and some don't(we call them "clients"). Every client needs to download the file from servers. When a client gets the WHOLE file, it becomes a server.

These computers are not always online. An online client will down load the file from all online servers. Different servers send data of different parts of the file to a client, so the client can download the file faster.

Now given the transfer speed between each pair of computers, what time is every computer online or offline, and which computers are servers at the beginning, please analyze the running of the system in a period of time.

Input

The first line contains an integer indicating the number of test cases.


For each test case:

Line 1: It contains two positive integers: n and T (n <= 20, T <= 1000) meaning that there are n computers in the system numbered from 1 to n, and you task is to figure out that how many percentage of the file does every computer gets after T seconds from the beginning.

Line 2: It contains two positive integers: k and S (k <= n, S <= 2 20) meaning that at the beginning there are k servers, and the size of the file of our concern is S (KB).

Line 3: It contains k integers. It's a list of all servers' No.

Line 4 ~ n+3: These n lines form a matrix of size n x n. The j-th integer in the i-th row of the matrix represents the transfer speed (in KB/s, no more than 210) between computer i and computer j (i and j start from 1). The matrix is symmetrical and the integers on the diagonal are meaningless.

Line n+4 ~ 2n+3: Each line contains an online/offline pattern for a computer in the following format (These lines are in the ascending order of computer No.):

t online_time 1 offline_time1 online_time 2 offline_time2...online_time t offline_timet


t is an integer no more than 10 and the time given are all non-negative integers and in ascending order. During the time between online_timei and offline_time i, the computer is online and can download data from other computers or send data to other computers.

Line 2n+4: It contains one positive integer m, representing the number of download actions in the system.

Line 2n+5 ~ 2n+m+4: Each line contains two integers representing a download action in the following format:

download_time i computer_idi


At time download_time i, the computer_idi computer starts to download the file, where 0 <= download_timei <= T, 1 <= computer_id i <= n.

These lines are given in non-descending order of time. It's guaranteed that servers never try to download the file. It's ensured that at time download_timei the computer computer_id i is online (Though it's possible that it instantly go offline after issuing a download command).

When a client starts to download, it will try to connect to all servers and download data simultaneously from online servers. The client's download speed is the sum of all connections. We assume the construction of a connection to be instant and cost no time. Only data transfer is time consuming.

When a client goes offline, unfinished download task will be saved and continued when it's online next time. If a server goes online, all computers that are currently downloading will connect to it and download data from it. What's more, when a client becomes a server, it begins to send data to clients immediately.


NOTE: To simplify the problem, time used to download a file should be rounded up to integer (If the file size is 6KB and download speed is 5KB/s, the download task will cost 2 seconds instead of 1.2 seconds -- 5KB for the first second and 1KB for the next second).

Please note that all times given above are in seconds.

Output

For each test case, the output should contain n lines, each for a computer.

The i-th line contains a percentage indicating the amount of data the i-th computer gets after T seconds from the beginning, in the format: 'percentage%'. The percentage should be rounded down to integer.

Sample Input

Sample input #1:12 501 102410 1010 01 0 501 10 40110 2Sample input #214 5002 2002 30 1 1 11 0 1 11 1 0 11 1 1 02 0 200 300 5001 100 2001 200 4001 301 50020 1301 4

Sample Output

Sample output #1:100%29%Sample output #2:100%100%100%99%

Hint

There are 2 computers. The file size is 1024 KB and Computer 1 is a server at the beginning. At time 10, computer 2 start to download that file from computer 1 until it goes offline at time 40. Totally 10KB/s x 30s = 300KB is downloaded. 300/1024 \approx 29%.

题意:
AC代码:
#include<iostream>#include<cstdio>#include<cstring>using namespace std;struct node{    int Time[1010];  //记录这个是时间是否工作    int Start;       //开机时间    int Server;     // 是否为服务器    int Size;       //目前的下载量    void clear()    {        memset(Time, 0, sizeof Time);        Start = 1e9;        Server = 0;        Size = 0;    }};int main(){    int Case;        int t;        scanf("%d", &t);        while (t--)        {            int N, T;            node Computer[30];            scanf("%d%d", &N, &T);  //电脑的台数   总时间            for (int i = 1; i <= N; i++)            {                Computer[i].clear();            }            int K, SIZE;            scanf("%d%d", &K, &SIZE);  //服务器的台数   下载文件的大小            for (int i = 1; i <= K; i++)            {                int x;                scanf("%d", &x);                Computer[x].Server = 1;                Computer[x].Size = SIZE;            }            int speed[30][30];            for (int i = 1; i <= N; i++)            {                for (int j = 1; j <= N; j++)                {                    scanf("%d", &speed[i][j]);  // i-j 两台电脑的传输速度                }            }            for (int i = 1; i <= N; i++)            {                int k;                scanf("%d", &k);  //第i台电脑的开关机时间段                while (k--)                {                    int l, r;                    scanf("%d%d", &l, &r);                      for (int j = l; j < r; j++) //左闭 右开  样例可知                    {                        if (j >= 0 && j <= T)                          {                            Computer[i].Time[j] = 1;  //标记当前时间可用                        }                    }                }            }            int num;              scanf("%d", &num); //num台电脑下载            for (int i = 1; i <= num; i++)            {                int x, y;                scanf("%d%d", &x, &y);  //电脑y在x时间开始下载                Computer[y].Start = x;            }            for (int i = 1; i < T; i++)            {                for (int k = 1; k <= N; k++)                {                    if (Computer[k].Server == 1) continue;  //服务器不用下载 默认下载完成                    for (int l = 1; l <= N; l++)                    {                        if (Computer[l].Server == 1 && Computer[k].Start <= i && Computer[k].Time[i] == 1 && Computer[l].Time[i] == 1)                            Computer[k].Size += speed[k][l];                    }                }                for (int j = 0; j <= N; j++)                {                    if (Computer[j].Size >= SIZE)  // 把文件下载完的电脑会转变为服务器                        Computer[j].Server = 1;                }            }            for (int i = 1; i <= N; i++)            {                if (Computer[i].Server == 1)                    printf("100%%\n");                else                {                    printf("%d%%\n", Computer[i].Size * 100 / SIZE);                }            }        }    return 0;}

0 0
原创粉丝点击