编程介的小学生 2019-10-31 21:57 采纳率: 20.5%
浏览 175

用代码具体怎么来做的Servers

Description

The Kingdom of Byteland decided to develop a large computer network of servers offering various services.

The network is built of n servers connected by bidirectional wires. Two servers can be directly connected by at most one wire. Each server can be directly connected to at most 10 other servers and every two servers are connected with some path in the network. Each wire has a fixed positive data transmission time measured in milliseconds. The distance (in milliseconds) d(V,W) between two servers V and W is defined as the length of the shortest (transmission time-wise) path connecting V and W in the network. For convenience we let d(V,V)=0 for all V.

Some servers offer more services than others. Therefore each server V is marked with a natural number r(V), called a rank. The bigger the rank the more powerful a server is.

At each server, data about nearby servers should be stored. However, not all servers are interesting. The data about distant servers with low ranks do not have to be stored. More specifically, a server W is interesting for a server V if for every server U such that d(v,U) ≤ d(V,W) we have r(U) ≤ r(W).

For example, all servers of the maximal rank are interesting to all servers. If a server V has the maximal rank, then exactly the servers of the maximal rank are interesting for V. Let B(V) denote the set of servers interesting for a server V.

We want to compute the total amount of data about servers that need to be stored in the network being the total sum of sizes of all sets B(V). The Kingdom of Byteland wanted the data to be quite small so it built the network in such a way that this sum does not exceed 30n.
Write a program that:
reads the description of a server network from the standard input,
computes the total amount of data about servers that need to be stored in the network,
writes the result to the standard output.
Input

In the first line there are two natural numbers n, m, where n is the number of servers in the network (1 <= n <= 30000) and m is the number of wires (1 <= m <= 5n)). The numbers are separated by single space.

In the next n lines the ranks of the servers are given. Line i contains one integer ri (1 <= ri <= 10) -- the rank of i-th server.

In the following m lines the wires are described. Each wire is described by three numbers a, b, t (11 <= t <= 1000, 1 <= a, b <= n, a ≠ b), where a and b are numbers of the servers connected by the wire and t is the transmission time of the wire in milliseconds.
Output

The output consists of a single integer equal to the total amount of data about servers that need to be stored in the network.
Sample Input

4 3
2
3
1
1
1 4 30
2 3 20
3 4 20
Sample Output

9

  • 写回答

1条回答 默认 最新

  • H_hermit1c6 2019-10-31 22:32
    关注

    翻译:
    题目说明:
    拜特兰王国决定开发一个由提供各种服务的服务器组成的大型计算机网络。
    网络由n台服务器组成,通过双向电线连接。两台服务器最多只能通过一根电线直接连接每台服务器最多可直接连接到10台其他服务器,每两台服务器都连接到网络中的某个路径。每条导线都有一个固定的正数据传输时间(以毫秒为单位)。两台服务器v和w之间的距离(以毫秒为单位)d(v,w)定义为连接网络中v和w的最短(按传输时间顺序)路径的长度。为了方便起见,我们让d(v,v)=0表示所有的v。
    有些服务器提供的服务比其他服务器多。因此,每个服务器v都用一个自然数r(v)标记,称为秩。级别越大,服务器的功能就越强大。
    在每台服务器上,应该存储有关附近服务器的数据。然而,并不是所有的服务器都有趣。不必存储低等级的远程服务器的数据。更具体地说,如果对于每台服务器u,使得d(v,u)≤d(v,w)我们有r(u)≤r(w),则服务器w对于服务器v是有趣的。
    例如,所有服务器的最大秩对所有服务器都是有趣的。如果服务器V具有最大秩,那么最大秩的服务器对于V是有趣的。让B(V)表示服务器V感兴趣的服务器集。
    我们希望计算需要存储在网络中的服务器的总数据量,即所有集合b(v)的大小之和。byteland王国希望数据非常小,所以它构建网络的方式不超过30n。

    编写一个程序:
    从标准输入读取服务器网络的描述,
    计算需要存储在网络中的服务器的数据总量,
    将结果写入标准输出。

    输入
    在第一行中有两个自然数n,m,其中n是网络中的服务器数(1<=n<=30000),m是电线数(1<=m<=5n)。数字用一个空格隔开。
    在接下来的n行中,给出了服务器的级别。第i行包含一个整数ri(1<=ri<=10)--第i个服务器的秩。
    在下面的m行中描述了这些导线。每根电线由三个数字A、B、T(11<=T<=1000,1<=A、B<=N,A≠B)描述,其中A和B是由电线连接的服务器的数量,T是电线的传输时间(以毫秒为单位)。

    输出
    输出由一个整数组成,该整数等于需要存储在网络中的服务器的总数据量。
    样例输入:
    4 3
    2
    3
    1
    1
    1 4 30
    2 3 20
    3 4 20
    样例输出:
    9

    评论

报告相同问题?

悬赏问题

  • ¥30 这是哪个作者做的宝宝起名网站
  • ¥60 版本过低apk如何修改可以兼容新的安卓系统
  • ¥25 由IPR导致的DRIVER_POWER_STATE_FAILURE蓝屏
  • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
  • ¥50 有数据,怎么用matlab求全要素生产率
  • ¥15 TI的insta-spin例程
  • ¥15 完成下列问题完成下列问题
  • ¥15 C#算法问题, 不知道怎么处理这个数据的转换
  • ¥15 YoloV5 第三方库的版本对照问题
  • ¥15 请完成下列相关问题!