A2. Good Matrix Elements

The Smart Beaver from ABBYY got hooked on square matrices. Now he is busy studying an n × n size matrix, where n is odd. The Smart Beaver considers the following matrix elements good:

Elements of the main diagonal.
Elements of the secondary diagonal.
Elements of the “middle” row — the row which has exactly rows above it and the same number of rows below it.
Elements of the “middle” column — the column that has exactly columns to the left of it and the same number of columns to the right of it.
The figure shows a 5 × 5 matrix. The good elements are marked with green.
Help the Smart Beaver count the sum of good elements of the given matrix.

Input
The first line of input data contains a single odd integer n. Each of the next n lines contains n integers aij (0 ≤ aij ≤ 100) separated by single spaces — the elements of the given matrix.

The input limitations for getting 30 points are:

1 ≤ n ≤ 5
The input limitations for getting 100 points are:

1 ≤ n ≤ 101
Output
Print a single integer — the sum of good matrix elements.

Examples
inputCopy
3
1 2 3
4 5 6
7 8 9
outputCopy
45
inputCopy
5
1 1 1 1 1
1 1 1 1 1
1 1 1 1 1
1 1 1 1 1
1 1 1 1 1
outputCopy
17
Note
In the first sample all matrix elements will be good. Good elements in the second sample are shown on the figure.

#include <iostream>
#include <algorithm>
using namespace std;

int a[105][105];

int main()
{
    int n;
    while(cin >> n)
    {
        int sum = 0;
        for(int i = 0; i < n; ++i)
            for(int j = 0; j < n; ++j)
                cin >> a[i][j];
        for(int i = 0; i < n; ++i)
            sum += a[n / 2][i];
        for(int i = 0; i < n; ++i)
            sum += a[i][n / 2];
        for(int i = 0; i < n; ++i)
            for(int j = 0; j < n; ++j)
                if(i == j || max(i, j) + min(i, j) == n - 1)
                    sum += a[i][j];///注意:最终间的数在这里仅被加了一次
        cout << sum - 2 * a[n / 2][n / 2] << '\n';
    }
    return 0;
}

<think>好的,我现在需要帮助用户验证Flume配置文件中节点2的设置是否正确,特别是使用Avro源和HDFS接收器的情况。首先,我应该回顾用户提供的引用内容,看看是否有相关的配置或步骤可以参考。 根据引用[2],用户提到了下载和安装Flume的步骤,说明他们可能已经正确安装了Flume,但需要验证配置是否正确。引用[3]和引用[4]中提到了查看HDFS中的文件以及使用Avro方式收集数据的情况,这可能与节点2的设置有关。 用户的问题是关于验证节点2的配置,其中包含Avro源和HDFS接收器。我需要考虑Flume配置文件的常见错误点,例如Avro源的绑定地址和端口是否正确,HDFS接收器的路径、文件前缀、滚动策略等参数是否合理。 首先,我应该建议用户检查配置文件的基本结构,确保每个组件(源、通道、接收器)的正确定义。然后,重点查看Avro源的hostname和port是否正确,确保没有与其他服务冲突。接着,检查HDFS接收器的HDFS路径是否有效,是否有写入权限,以及滚动配置是否合理,比如文件大小或事件数量触发滚动。 另外,引用[3]中提到使用hadoop fs -ls命令查看HDFS中的文件,这可以用来验证数据是否成功写入。用户可能需要手动发送测试数据到Avro源,然后检查HDFS中是否有新文件生成,或者是否有临时文件存在,这可能意味着文件正在被写入但未满足滚动条件。 同时,启动Flume时的日志信息也很重要,需要检查是否有错误或警告信息,特别是关于配置验证的部分。例如,如果Avro源无法绑定到指定端口,或者HDFS接收器无法连接到Hadoop集群,这些都会在日志中体现。 可能还需要考虑网络问题,比如节点之间的防火墙设置是否允许Avro端口的通信,以及Hadoop集群的可达性。此外,用户的Hadoop配置是否正确,比如core-site.xml中的HDFS地址,是否被Flume正确读取。 最后,建议用户分步骤验证,从配置文件语法检查开始,到启动Flume并监控日志,发送测试数据,最后检查HDFS输出。这样逐步排查可以定位问题所在,确保节点2的配置正确无误。</think>### Flume节点2配置验证步骤(Avro源 + HDFS接收器) #### 1. 配置文件基础验证 检查配置文件是否包含以下核心元素: ```properties # 节点2配置示例 agent.sources = avroSource agent.channels = memChannel agent.sinks = hdfsSink # Avro源配置(需与上游节点地址匹配) agent.sources.avroSource.type = avro agent.sources.avroSource.bind = 0.0.0.0 # 需验证是否为实际IP[^2] agent.sources.avroSource.port = 4545 # 需验证端口是否开放 # 内存通道配置 agent.channels.memChannel.type = memory agent.channels.memChannel.capacity = 1000 # HDFS接收器配置(检查路径权限) agent.sinks.hdfsSink.type = hdfs agent.sinks.hdfsSink.hdfs.path = hdfs://namenode:8020/flume/events/%y-%m-%d/%H%M agent.sinks.hdfsSink.hdfs.filePrefix = events- agent.sinks.hdfsSink.hdfs.rollSize = 134217728 # 128MB滚动[^3] ``` #### 2. 网络连通性验证 ```bash # 检查端口监听状态 netstat -tuln | grep 4545 # 测试Avro端口可达性(从发送节点) telnet node2-ip 4545 ``` #### 3. HDFS写入权限验证 ```bash # 手动创建测试目录(需与配置路径一致) hadoop fs -mkdir -p /flume/events hadoop fs -chmod -R 777 /flume/events # 临时赋权[^3] ``` #### 4. 启动过程监控 ```bash # 带调试模式启动Flume bin/flume-ng agent -n agent -c conf -f conf/node2.conf -Dflume.root.logger=INFO,console ``` 观察以下关键日志: - `Avro source avroSource started` 表示源启动成功 - `Successfully connected to hdfs://namenode:8020` 表示HDFS连接正常 #### 5. 数据流验证 ```bash # 使用avro-client发送测试数据 bin/flume-ng avro-client -H node2-ip -p 4545 -F test.log ``` 验证HDFS文件生成: ```bash hadoop fs -ls /flume/events/*/* | grep .tmp # 检查写入中的临时文件[^3] hadoop fs -tail /flume/events/最新文件路径 # 查看数据内容 ``` #### 常见故障点排查 1. **HDFS路径权限问题**:`Permission denied`错误需检查HDFS ACL 2. **端口冲突**:`BindException`需更换端口或释放占用端口 3. **滚动策略失效**:确保同时设置`rollSize`和`rollInterval` 4. **时区问题**:路径中的`%y-%m-%d`可能产生非预期目录
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值