ZOJ Problem Set - 3277
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.
The first line contains an integer indicating the number of test cases.
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.
For each test case, the output should contain n lines, each for a computer.
1 2 50 1 1024 1 0 10 10 0 1 0 50 1 10 40 1 10 2
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 * 30s = 300KB is downloaded. 300/1024 ≈ 29%.
1 4 500 2 200 2 3 0 1 1 1 1 0 1 1 1 1 0 1 1 1 1 0 2 0 200 300 500 1 100 200 1 200 400 1 301 500 2 0 1 301 4
Sample Output 2
100% 100% 100% 99%
Source: Asia 2009, Ningbo (Mainland China)