poj 3836 P2P File Sharing System

这题是一个模拟p2p的网络的一个题目。题意比较繁琐,只要看懂课,细心一点就很好AC了。直接上代码了,存模拟。

#include<stdio.h>
#include<string.h>
#include<iostream>
#include<string>
#include<queue>
#include<cmath>
#include<map>
#include<algorithm>
#include<vector>
#include<bitset>
using namespace std;

const int inf = 0x3fffffff;
const int mmax = 1010;
bool Server[30];
bool Online[30][mmax];
int Speed[30][30];
int Start_time[30];
int Large[30];
int n,T,k,S;
void download(int nowtime, int c_id)
{
    int sum=0;
    for(int i=1;i<=n;i++)
    {
        if(Server[i] && Online[i][nowtime])
        {
            sum+=Speed[i][c_id];
        }
    }
    Large[c_id]+=sum;
}
int main()
{
    int Case;
    scanf("%d",&Case);
    while(Case--)
    {
        scanf("%d %d",&n,&T);
        scanf("%d %d",&k,&S);
        memset(Server,0,sizeof Server);
        memset(Online,0,sizeof Online);
        for(int i=0;i<k;i++)
        {
            int x;
            scanf("%d",&x);
            Server[x]=1;
        }
        for(int i=1;i<=n;i++)
            for(int j=1;j<=n;j++)
            {
                scanf("%d",&Speed[i][j]);
                if(i==j)
                    Speed[i][j]=0;
            }
        int t;
        for(int i=1;i<=n;i++)
        {
            scanf("%d",&t);
            while(t--)
            {
                int st,en;
                scanf("%d %d",&st,&en);
                en=min(en,T+1);
                for(int j=st+1;j<=en;j++)
                    Online[i][j]=1;
            }
        }
        for(int i=1;i<=n;i++)
            Start_time[i]=inf;
       //cout<<Start_time[1]<<endl;

        int m;
        scanf("%d",&m);
        while(m--)
        {
            int download_time,computer_id;
            scanf("%d %d",&download_time,&computer_id);
            Start_time[computer_id]=min(Start_time[computer_id],download_time);
        }
        memset(Large,0,sizeof Large);
        for(int i=1;i<=T;i++)
        {
            for(int j=1;j<=n;j++)
            {
                if(!Server[j]&& Start_time[j]<i && Online[j][i])
                    download(i,j);
            }
            for(int j=1;j<=n;j++)
            {
                if(Large[j]>=S)
                {
                    Server[j]=1;
                    Large[j]=S;
                }
            }
        }
//        for(int i=1;i<=n;i++)
//        {
//            cout<<Large[i]<<" ";
//        }
//        cout<<endl;

        for(int i=1;i<=n;i++)
        {
            if(Server[i])
                printf("100%%\n");
            else
                printf("%d%%\n",Large[i]*100/S);
        }

    }
    return 0;
}
时间: 2025-01-06 19:18:35

poj 3836 P2P File Sharing System的相关文章

Another option for file sharing(转)

原文地址  https://security.googleblog.com/2017/02/another-option-for-file-sharing.html Another option for file sharing February 21, 2017 Posted by Andrew Gerrand, Eric Grosse, Rob Pike, Eduardo Pinheiro and Dave Presotto, Google Software Engineers Existi

Adding AirDrop File Sharing Feature to Your iOS Apps

http://www.appcoda.com/ios7-airdrop-programming-tutorial/ Adding AirDrop File Sharing Feature to Your iOS Apps october 30, 2013 by simon ng 12 comments AirDrop is Apple’s answer to file and data sharing. Before the debut of iOS 7, users need to rely

POJ #2448 A New Operating System

Time Limit: 20000MS   Memory Limit: 65536K Total Submissions: 1165   Accepted: 110 Case Time Limit: 5000MS Description May is a lovely girl. Due to her filial piety, she wants to give a present on her mother's birthday. Because both her parents are t

File类--System.out.print(Object obj)的理解

一.File 类(java.io) 概述:Java中使用File类来表示文件或者文件夹对象!     抽象路径名:描述文件或文件夹时,使用的路径符号,就是一个对象的字符串表示形式,如"c:\\";     绝对路径:绝对位置开始的路径;     相对路径:相对位置开始的路径; 构造方法:     File(String pathname)     File(String parent, String child)     File(File parent, String child)

609. Find Duplicate File in System(LeetCode)

Given a list of directory info including directory path, and all the files with contents in this directory, you need to find out all the groups of duplicate files in the file system in terms of their paths. A group of duplicate files consists of at l

Android File Hierarchy : System Structure Architecture Layout

Most of the Android user are using their Android phone just for calls, SMS, browsing and basic apps, But form the development prospective, we should know about  Android internal structure. Android uses several partitions (like boot, system, recovery,

[LeetCode] Find Duplicate File in System 在系统中寻找重复文件

Given a list of directory info including directory path, and all the files with contents in this directory, you need to find out all the groups of duplicate files in the file system in terms of their paths. A group of duplicate files consists of at l

POJ 1023 The Fun Number System

Description In a k bit 2's complement number, where the bits are indexed from 0 to k-1, the weight of the most significant bit (i.e., in position k-1), is -2^(k-1), and the weight of a bit in any position i (0 ≤ i < k-1) is 2^i. For example, a 3 bit

609. Find Duplicate File in System

寻找重复文件的路径集合 /* 没有什么特别的技巧,就是用map存储相同内容的路径,核心就是getOrDefault()方法 注意步骤,想清楚思路 */ //记录结果 Map<String,ArrayList> map = new HashMap<>(); for (String path : paths) { //把根路径和各个文件分开 String[] files = path.split(" "); //遍历每个文件,有两个任务,一是存下改文件内容,二是把该