HDU 3269 P2P File Sharing System(模拟)(2009 Asia Ningbo Regional Contest)
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.
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.
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.
#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)的更多相关文章
- 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 ...
- 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 ...
- 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 ...
- 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 ...
- HDU 3126 Nova [2009 Asia Wuhan Regional Contest Online]
标题效果 有着n巫妖.m精灵.k木.他们都有自己的位置坐标表示.冷却时间,树有覆盖范围. 假设某个巫妖攻击精灵的路线(他俩之间的连线)经过树的覆盖范围,表示精灵被树挡住巫妖攻击不到.求巫妖杀死所有精灵 ...
- 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 ...
- 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 ...
- 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 ...
- hdu 3123 2009 Asia Wuhan Regional Contest Online
以为有啥牛逼定理,没推出来,随便写写就A了----题非常水,可是wa了一次 n>=m 则n!==0 注意的一点,最后 看我的凝视 #include <cstdio> #includ ...
随机推荐
- LeetCode11.盛最多水的容器 JavaScript
给定 n 个非负整数 a1,a2,...,an,每个数代表坐标中的一个点 (i, ai) .在坐标内画 n 条垂直线,垂直线 i 的两个端点分别为 (i, ai) 和 (i, 0).找出其中的两条线, ...
- 【HDOJ 1272】小希的迷宫(并查集+无环图)
描述 上次Gardon的迷宫城堡小希玩了很久(见Problem B),现在她也想设计一个迷宫让Gardon来走.但是她设计迷宫的思路不一样,首先她认为所有的通道都应该是双向连通的,就是说如果有一个通道 ...
- Linux centos7 安装python3 及 GCC
1.用wget下载python源码 PYTHON下载 找适合自己的版本,我下载的是3.7.2 2.用tar命令解压下载的文件 tar -zxvf Python-3.7.2.tgz 3.进入目录解压后的 ...
- Java OOP——第四章 异常
1. 接口:接口就是给出一些没有内容的方法,封装到一起,到某个类要使用的时候,在根据具体情况把这些方法写出来. 接口是更加抽象的抽象的类, 抽象类里的方法可以有方法体, 接口里的所有方法都没有方法体. ...
- Django---admin简单功能
admin admin是django强大功能之一,它能共从数据库中读取数据,呈现在页面中,进行管理.默认情况下,它的功能已经非常强大,如果你不需要复杂的功能,它已经够用,但是有时候,一些特殊的功能还需 ...
- Generating Complex Procedural Terrains Using GPU
前言:感慨于居然不用tesselation也可以产生这么复杂的地形,当然致命的那个关于不能有洞的缺陷还是没有办法,但是这个赶脚生成的已经足够好了,再加上其它模型估 计效果还是比较震撼的.总之好文共分享 ...
- mongodb的高级查询
db的帮助文档 输入:db.help(); db.AddUser(username,password[, readOnly=false]) 添加用户 db.auth(usrename,passwor ...
- Python实现多属性排序
Python实现多属性排序 多属性排序:假如某对象有n个属性,那么先按某规则对属性a进行排序,在属性a相等的情况下再按某规则对属性b进行排序,以此类推. 现有对象Student: class Stud ...
- hive 学习系列五(hive 和elasticsearch 的交互,很详细哦,我又来吹liubi了)
hive 操作elasticsearch 一,从hive 表格向elasticsearch 导入数据 1,首先,创建elasticsearch 索引,索引如下 curl -XPUT '10.81.17 ...
- Leecode刷题之旅-C语言/python-100相同的树
/* * @lc app=leetcode.cn id=100 lang=c * * [100] 相同的树 * * https://leetcode-cn.com/problems/same-tree ...