感觉是因为自己的能力不够,这三题真的写了很久也还没思路。对C++也不是很熟悉,真的尽力了。有大佬有思路欢迎交流。
用ChatGPT把图片转换成文本,方便阅读。明天思考一下来写代码。
There are n
servers in the network arranged in ascending order of their capacity. In the array capacity
, the capacity of the ith server is capacity[i]
, where 0 ≤ i < n
.
The distance between two servers, i and j, is defined as the absolute difference in their capacities: |capacity[i] - capacity[j]|
. For each server i, the closest server j is the one with the smallest distance to i, and this closest server is unique.
To manage the network, the following operations can be done to server x:
|capacity[x] - capacity[y]|
units.Given m
queries, each defined by two integers fromServer[i]
and toServer[i]
, find the minimum cost required to connect from fromServer[i]
to toServer[i]
for each query. The connection can be either direct or routed through a server z.
Note:
capacity
array are distinct.n = 3, m = 3
capacity = [2, 7, 10]
fromServer = [0, 1, 2]
toServer = [2, 2, 1]
Starting server | Ending server | Path | Cost |
---|---|---|---|
0 | 2 | 0 → 1 → 2 | 1 + 1 = 2 |
1 | 2 | 1 → 2 | 1 |
2 | 1 | 2 → 1 | 1 |
|2 - 7| < |2 - 10|
|7 - 10| < |7 - 2|
|10 - 7| < |10 - 2|