Problem 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<=220) 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*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_time1 offline_time1 online_time1 offline_time2 ... online_timet 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_timei, 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_timei computer_idi
At time download_timei, the computer computer_idi starts to download the file. 0<= download_timei <=T, 1<= computer_idi <=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_idi 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.
 
题目大意:模拟一个文件的P2P发送和接受。
思路:模拟题,不是很难,就是题目略长。
 
 #include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std; const int MAXT = ;
const int MAXN = ; int mat[MAXN][MAXN], state[MAXN][MAXT];
int download[MAXN], beg[MAXN];
int n, m, k, T, size; void init() {
memset(download, , sizeof(download));
memset(state, , sizeof(state));
scanf("%d%d", &n, &T);
scanf("%d%d", &k, &size);
while(k--) {
int x;
scanf("%d", &x);
download[x] = size;
}
for(int i = ; i <= n; ++i)
for(int j = ; j <= n; ++j) scanf("%d", &mat[i][j]);
for(int i = ; i <= n; ++i) {
int t, st, ed;
scanf("%d", &t);
while(t--) {
scanf("%d%d", &st, &ed);
for(int j = st; j < ed; ++j) state[i][j] = ;
}
}
scanf("%d", &m);
memset(beg, 0x3f, sizeof(beg));
while(m--) {
int t, id;
scanf("%d%d", &t, &id);
beg[id] = t;
}
} void solve() {
for(int t = ; t < T; ++t) {
for(int i = ; i <= n; ++i) {
if(download[i] == size || beg[i] > t) continue;
if(!state[i][t]) continue;
int sum = ;
for(int j = ; j <= n; ++j) {
if(download[j] != size) continue;
if(!state[j][t]) continue;
sum += mat[i][j];
}
download[i] += sum;
if(download[i] >= size) download[i] = size + ;
}
for(int i = ; i <= n; ++i)
if(download[i] == size + ) --download[i];
}
} void output() {
for(int i = ; i <= n; ++i) {
printf("%d%%\n", download[i] * / size);
}
} int main() {
int kase;
scanf("%d", &kase);
while(kase--) {
init();
solve();
output();
}
}

HDU 3269 P2P File Sharing System(模拟)(2009 Asia Ningbo Regional Contest)的更多相关文章

  1. hdu 3123 GCC (2009 Asia Wuhan Regional Contest Online)

    GCC Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others) Total Subm ...

  2. hdu oj 3127 WHUgirls(2009 Asia Wuhan Regional Contest Online)

    WHUgirls Time Limit: 3000/2000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others) Total ...

  3. HDU 3262/POJ 3829 Seat taking up is tough(模拟+搜索)(2009 Asia Ningbo Regional)

    Description Students often have problems taking up seats. When two students want the same seat, a qu ...

  4. HDU 3265/POJ 3832 Posters(扫描线+线段树)(2009 Asia Ningbo Regional)

    Description Ted has a new house with a huge window. In this big summer, Ted decides to decorate the ...

  5. HDU 3126 Nova [2009 Asia Wuhan Regional Contest Online]

    标题效果 有着n巫妖.m精灵.k木.他们都有自己的位置坐标表示.冷却时间,树有覆盖范围. 假设某个巫妖攻击精灵的路线(他俩之间的连线)经过树的覆盖范围,表示精灵被树挡住巫妖攻击不到.求巫妖杀死所有精灵 ...

  6. HDU 3260/POJ 3827 Facer is learning to swim(DP+搜索)(2009 Asia Ningbo Regional)

    Description Facer is addicted to a game called "Tidy is learning to swim". But he finds it ...

  7. HDU 3264/POJ 3831 Open-air shopping malls(计算几何+二分)(2009 Asia Ningbo Regional)

    Description The city of M is a famous shopping city and its open-air shopping malls are extremely at ...

  8. HDU 3268/POJ 3835 Columbus’s bargain(最短路径+暴力枚举)(2009 Asia Ningbo Regional)

    Description On the evening of 3 August 1492, Christopher Columbus departed from Palos de la Frontera ...

  9. hdu 3123 2009 Asia Wuhan Regional Contest Online

    以为有啥牛逼定理,没推出来,随便写写就A了----题非常水,可是wa了一次 n>=m  则n!==0 注意的一点,最后 看我的凝视 #include <cstdio> #includ ...

随机推荐

  1. Navicat Premium 连接Oracle 数据库之配置

    Navicat Premium连接Oracle 数据库之配置 1.Oracle数据库服务器下载 Oracle官方网站下载数据库最新版本:http://www.oracle.com/technetwor ...

  2. iOS之一些实用的Demo

    图像浏览及处理 FLAnimatedImage - gif播放处理的工具. CLImageEditor - 超强的图片编辑库,快速帮你实现旋转,防缩,滤镜等等一系列麻烦的事情. ios-image-f ...

  3. node读写文件

    结束了一天的工作和学习,今天对于自己最大的收获就是node读写文件和对callback函数有了更深一步的理解.总结一下node读写的文件的注意事项吧(注意:下面讲的是增加数据的方法): 1.我们可以封 ...

  4. CentOS下删除MySql

    1.查找以前是否装有mysql rpm -qa | grep -i mysql 显示之前安装了: MySQL-client-5.5.49-1.linux2.6.i386 MySQL-server-5. ...

  5. 你知道JQuery中的事件冒泡吗,他是怎么执行的,如何来停止冒泡事件?

    事件冒泡 首先需要知道什么是事件冒泡? 事件冒泡是从里面的往外面开始触发的,就是点击子节点,会向上触发父节点,祖先节点的点击事件 demo: <html xmlns="http://w ...

  6. 【基于不同设备厂商在处理vlan之间通信配置例子】

    H3C: Dot1q子接口实现vlan之间的通信 一:根据项目需求搭建好拓扑图如下: 二:配置 HUAWEI: CISCO

  7. 为何要搭建ES6开发环境,如何搭建ES6开发环境?

    1.ES6需要搭建开发环境,原因是现在的Chrome浏览器已经支持ES6了,但是有些低版本的浏览器还是不支持ES6语法的,这就需要我们把ES6的语法自动转变成ES5的语法.   2.开始搭建环境   ...

  8. Linux Shell常用命令(长期更新)

    #判断某个字段是否匹配指定值 awk -F"," '{if($4=="value"){print $1} else {print $0}}' file.txt ...

  9. fabric Report API

    1.Token生成 接口 : post https://fabric.io/oauth/token 请求头:Headers Content-Type : application/json 正文: bo ...

  10. Hadoop(2)-CentOS下的jdk和hadoop的安装与配置

    准备工作 下载jdk8和hadoop2.7.2 使用sftp的方式传到hadoop100上的/opt/software目录中 配置环境 如果安装虚拟机时选择了open java,请先卸载 rpm -q ...