牛客网 NC13812 Another Server 简单题

牛客网 NC13812 Another Server

目录

1. 题目描述

1.1. Limit

Time Limit: 1000 ms

Memory Limit: 262144 kB

1.2. Problem Description

何老师某天在机房里搞事情的时候,发现机房里有n台服务器,从 1 1 n n 标号,同时有 2 n 2 2n-2 条网线,从 1 1 2 n 2 2n-2 标号,其中第i条网线双向连接着 服务器和号服务器,在一个单位时间内最多能够承受 x i x_i 个单位流量。 显然这些服务器之间要进行信息交换,为了测试服务器的抗压能力,你需要帮何老师计算出 1 1 号服务器在一个单位时间内最多能向 n n 号服务器发送多少个单位流量的数据,这里认为数据的传输是瞬间完成的。


1.3. Input

第一行是一个正整数 T ( 1000 ) T(\le 1000) ,表示测试数据的组数, 对于每组测试数据, 第一行是一个整数 n ( 2 n 100 ) n(2 \le n \le 100) ,表示服务器的数量, 第二行包含2n-2个以空格分隔的正整数 x 1 , x 2 , . . . , x 2 n 2 x_1,x_2,...,x_{2n-2} ,表示网线单位时间内能承受的流量,保证不超过100。


1.4. Output

对于每组测试数据,输出一个整数,表示 1 1 号服务器在一个单位时间内最多能向 n n 号服务器发送的数据量。


1.5. Sample Input

2
2
1 1
3
1 3 2 4

1.6. Sample Output

2
4

1.7. Source

牛客网 NC13812 Another Server


2. 解读

求每两根线能量之和的最小值,即对 2 n 2n 2 n 1 2n-1 两项进行求和 s u m n sum_n ,求最小值 min s u m n \min sum_n

3. 代码

#include <iostream>
#include <string.h>
using namespace std;

const int NUM = 1e3 + 1;
// 存储
long long list[NUM];

int main()
{
    // test case
    int t, n;
    scanf("%d", &t);
    // 每两根线能量之和的最小值
    long long minSum;
    // test case
    for (int i = 0; i < t; i++) {
        // 机器数量
        scanf("%d", &n);
        // 初始化
        memset(list, 0, sizeof(list));
        // 输入
        for (int j = 0; j < 2 * n - 2; j++) {
            scanf("%lld", &list[j]);
        }
        // 计算
        // 初始化
        minSum = list[0] + list[1];
        // 求每两根线能量之和的最小值
        for (int i = 1; i < n - 1; i++) {
            minSum = min(minSum, list[2 * i] + list[2 * i + 1]);
        }
        // 输出
        printf("%lld\n", minSum);
    }
}

联系邮箱:[email protected]

Github:https://github.com/CurrenWong

欢迎转载/Star/Fork,有问题欢迎通过邮箱交流。

猜你喜欢

转载自blog.csdn.net/qq_41729780/article/details/106132881
今日推荐