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 ...
随机推荐
- sysdate 和 current_date 的区别
在oracle中current_date与sysdate都是显示当前系统时间, 其结果基本相同,但是有三点区别: 1. current_date返回的是当前会话时间,而sysdate返回的是服务器时间 ...
- JDBC相关
//原生jdbc操作案例 import java.sql.Connection; import java.sql.DriverManager; import java.sql.ResultSet; i ...
- ABAP术语-Event
Event 原文:http://www.cnblogs.com/qiangsheng/archive/2008/01/31/1059588.html Occurrence of a change of ...
- python 之函数
一 函数的定义:对功能和动作的封装和定义.二 函数的格式:def 函数名(形参列表): 函数名就是变量名:规则就是变量的规则 函数体(return) ret = 函数名(实参列表)三 函数的返回值:函 ...
- idea中注解配置一对多,多对一,双向多对一映射(不详细)
一对多 package cn.pojo; import javax.persistence.*; import java.io.Serializable; import java.util.Set; ...
- Docker(三):部署软件
Docker的镜像文件可以在镜像仓库中进行搜索. 部署软件目录导航: 常用命令 部署 Tomcat 部署 MySQL 部署 Oracle 常用命令 docker的常用命令如下: docker -v , ...
- Apache Maven(五):插件
Maven的插件分如下两种: build plugins:该插件在项目构建阶段执行,它们都在<build>标签中设置. reporting plugins : 该插件在网站生成期间执行,他 ...
- .Net Core On Liunx 环境搭建之 Docker 容器和Nginx
上一篇文章安装了Mysql8数据库,接下开始安装Docker和Nginx 我的思路是这样的,用Docker当运行环境的虚拟机,Nginx当Http服务器用来做反向代理. 服务器环境:阿里云服务器,操作 ...
- Hadoop(19)-MapReduce框架原理-Combiner合并
1. Combiner概述 2. 自定义Combiner实现步骤 1). 定义一个Combiner继承Reducer,重写reduce方法 public class WordcountCombiner ...
- 一些斗鱼TV Web API [Some DouyuTv API]
一些斗鱼TV Web API [Some DouyuTv API] 写在最前 去年TI5前开发了dotaonly.com,网站需要用到各个直播平台API.不像国外网站Twitch那样开放,都有现成 ...