1296: 实验2-1-4 三点中值滤波 / Three-Point Median Filtering
Memory Limit:128 MB
Time Limit:1.000 S
Judge Style:Text Compare
Creator:
Submit:104
Solved:94
Description
【中文题面】
在心电、血压、呼吸、血氧等生物医学信号采集中,传感器接触不稳、肢体运动或瞬时电干扰都可能产生短暂的异常尖峰。
如果这些尖峰不经过处理,后续程序可能会误判心率过快、血压突变或报警事件。简单滤波可以在保留主要趋势的同时削弱这类孤立噪声。
本题给出一段整数信号序列。请对序列做三点中值滤波:除第一个和最后一个数据外,每个位置的新值等于它左侧、当前位置、右侧三个数的中位数。
第一个和最后一个数据没有完整的左右邻居,输出时保持原值不变。
例如序列 80 82 200 83 84 中,200 是一个孤立尖峰,它左右相邻的三个数为 82、200、83,中位数为 83,因此滤波后该位置变为 83。
建议定义并调用函数:void medianFilter3(const int src[], int dst[], int n)。
[English Statement]
In biomedical signal acquisition, such as ECG, blood pressure, respiration, and blood oxygen monitoring, unstable sensor contact, body movement, or short electrical interference may create temporary spikes.
If these spikes are not processed, later programs may incorrectly detect tachycardia, sudden pressure changes, or alarm events. Simple filtering can reduce isolated noise while preserving the main trend.
Given an integer signal sequence, apply three-point median filtering. Except for the first and last values, each output value is the median of the left value, the current value, and the right value.
The first and last values do not have two neighbors, so they remain unchanged.
For example, in 80 82 200 83 84, the value 200 is an isolated spike. The three values 82, 200, and 83 have median 83, so this position becomes 83 after filtering.
Suggested function: void medianFilter3(const int src[], int dst[], int n).
在心电、血压、呼吸、血氧等生物医学信号采集中,传感器接触不稳、肢体运动或瞬时电干扰都可能产生短暂的异常尖峰。
如果这些尖峰不经过处理,后续程序可能会误判心率过快、血压突变或报警事件。简单滤波可以在保留主要趋势的同时削弱这类孤立噪声。
本题给出一段整数信号序列。请对序列做三点中值滤波:除第一个和最后一个数据外,每个位置的新值等于它左侧、当前位置、右侧三个数的中位数。
第一个和最后一个数据没有完整的左右邻居,输出时保持原值不变。
例如序列 80 82 200 83 84 中,200 是一个孤立尖峰,它左右相邻的三个数为 82、200、83,中位数为 83,因此滤波后该位置变为 83。
建议定义并调用函数:void medianFilter3(const int src[], int dst[], int n)。
[English Statement]
In biomedical signal acquisition, such as ECG, blood pressure, respiration, and blood oxygen monitoring, unstable sensor contact, body movement, or short electrical interference may create temporary spikes.
If these spikes are not processed, later programs may incorrectly detect tachycardia, sudden pressure changes, or alarm events. Simple filtering can reduce isolated noise while preserving the main trend.
Given an integer signal sequence, apply three-point median filtering. Except for the first and last values, each output value is the median of the left value, the current value, and the right value.
The first and last values do not have two neighbors, so they remain unchanged.
For example, in 80 82 200 83 84, the value 200 is an isolated spike. The three values 82, 200, and 83 have median 83, so this position becomes 83 after filtering.
Suggested function: void medianFilter3(const int src[], int dst[], int n).
Input
【输入】
第一行输入整数 n。
第二行输入 n 个整数,表示原始信号序列。
数据保证 1 <= n <= 100,所有信号值均为整数。
[Input]
The first line contains n.
The second line contains n integers, representing the original signal sequence.
It is guaranteed that 1 <= n <= 100.
第一行输入整数 n。
第二行输入 n 个整数,表示原始信号序列。
数据保证 1 <= n <= 100,所有信号值均为整数。
[Input]
The first line contains n.
The second line contains n integers, representing the original signal sequence.
It is guaranteed that 1 <= n <= 100.
Output
【输出】
输出一行 n 个整数,表示三点中值滤波后的序列。
[Output]
Print one line with n integers, representing the sequence after three-point median filtering.
输出一行 n 个整数,表示三点中值滤波后的序列。
[Output]
Print one line with n integers, representing the sequence after three-point median filtering.
Sample Input Copy
7
80 82 200 83 84 10 85
Sample Output Copy
80 82 83 84 83 84 85
HINT
【拓展练习与 AI 使用建议】
拓展练习:把三点中值滤波改为三点平均滤波,即中间位置输出左右和自身三个数的整数平均值。
向 AI 提问时,要求使用普通数组、循环和函数,不要使用 vector、sort、类或复杂库函数。中位数可以用三个 if 语句或一个很小的辅助函数求出。
读懂代码时重点检查两个边界位置是否保持不变,以及第 i 个输出是否只使用原数组 src[i-1]、src[i]、src[i+1],不要在计算时把已经滤波后的值继续拿来用。
[Extension and AI Advice]
Extension: change three-point median filtering to three-point average filtering, where each middle position outputs the integer average of itself and its two neighbors.
When prompting AI, require ordinary arrays, loops, and functions. Avoid vector, sort, classes, or complex libraries. The median of three values can be found with a few if statements or a tiny helper function.
When reading the code, check that the two boundary values remain unchanged and that output position i uses only src[i-1], src[i], and src[i+1], not already-filtered values.
拓展练习:把三点中值滤波改为三点平均滤波,即中间位置输出左右和自身三个数的整数平均值。
向 AI 提问时,要求使用普通数组、循环和函数,不要使用 vector、sort、类或复杂库函数。中位数可以用三个 if 语句或一个很小的辅助函数求出。
读懂代码时重点检查两个边界位置是否保持不变,以及第 i 个输出是否只使用原数组 src[i-1]、src[i]、src[i+1],不要在计算时把已经滤波后的值继续拿来用。
[Extension and AI Advice]
Extension: change three-point median filtering to three-point average filtering, where each middle position outputs the integer average of itself and its two neighbors.
When prompting AI, require ordinary arrays, loops, and functions. Avoid vector, sort, classes, or complex libraries. The median of three values can be found with a few if statements or a tiny helper function.
When reading the code, check that the two boundary values remain unchanged and that output position i uses only src[i-1], src[i], and src[i+1], not already-filtered values.