Symmetric Order


Description

In your job at Albatross Circus Management (yes, it's run by a bunch of clowns), you have just finished writing a program whose output is a list of names in nondescending order by length (so that each name is at least as long as the one preceding it). However, your boss does not like the way the output looks, and instead wants the output to appear more symmetric, with the shorter strings at the top and bottom and the longer strings in the middle. His rule is that each pair of names belongs on opposite ends of the list, and the first name in the pair is always in the top part of the list. In the first example set below, Bo and Pat are the first pair, Jean and Kevin the second pair, etc. 

Input

The input consists of one or more sets of strings, followed by a final line containing only the value 0. Each set starts with a line containing an integer, n, which is the number of strings in the set, followed by n strings, one per line, sorted in nondescending order by length. None of the strings contain spaces. There is at least one and no more than 15 strings per set. Each string is at most 25 characters long.

Output

For each input set print "SET n" on a line, where n starts at 1, followed by the output set as shown in the sample output.

Sample Input

7
Bo
Pat
Jean
Kevin
Claude
William
Marybeth
6
Jim
Ben
Zoe
Joey
Frederick
Annabelle
5
John
Bill
Fran
Stan
Cece
0

Sample Output

SET 1
Bo
Jean
Claude
Marybeth
William
Kevin
Pat
SET 2
Jim
Zoe
Frederick
Annabelle
Joey
Ben
SET 3
John
Fran
Cece
Stan
Bill

 public void printResult() {
        int cases = 1;
        int n = 0;
        String[] str = new String[26];
        Scanner scan = new Scanner(System.in);
        while (true) {
            n = scan.nextInt();
            if (n == 0) {
                break;
            }
            for (int i = 0; i < n; ++i) {
                str[i] = scan.next();

            }
            System.out.println("SET " + cases);
            ++cases;
            for (int i = 0; i < n; i += 2) {
                System.out.println(str[i]);
            }
            if (n % 2 == 0) {
                for (int i = n - 1; i > 0; i -= 2) {
                    System.out.println(str[i]);
                }
            } else {
                for (int i = n - 2; i > 0; i -= 2) {
                    System.out.println(str[i]);
                }
            }
        }
    }

原先的序列变成了0,2,4,....(若N是奇数)N-2,....1或0,2,4,....(若N是偶数)N-1,.....,1

% 1. 读取并预处理SAR图像(替换为你的图像路径) sar_image = imread('sar_test.png'); % 输入SAR图像(灰度图) sar_double = double(sar_image); sar_log = log(sar_double + 1e-6); % 对数变换:乘性噪声→加性噪声(避免log(0)) % 2. 参数设置(新手推荐初始值) filter_order = 3; % 滤波器尺寸(3x3,平衡去噪与细节) mu = 0.02; % 步长(0.01~0.1,小了慢、大了抖) pad_size = floor(filter_order/2); % 边界填充尺寸 % 3. 边界填充(避免边缘越界) padded_log = padarray(sar_log, [pad_size pad_size], 'symmetric'); % 4. 初始化变量 [rows, cols] = size(sar_log); weights = zeros(filter_order); % 滤波器权重 filtered_log = zeros(rows, cols); % 滤波后的对数图像 % 5. LMS滤波核心循环 for i = 1:rows for j = 1:cols % 提取当前像素的邻域窗口 window = padded_log(i:i+filter_order-1, j:j+filter_order-1); window_vec = window(:); % 转为列向量 % 期望信号(无参考时用邻域均值替代,贴近实际场景) desired = mean(window_vec); % LMS更新:权重 = 权重 + 2*mu*误差*输入 error = desired - weights(:)' * window_vec; weights(:) = weights(:) + 2 * mu * error * window_vec; % 滤波输出(当前像素) filtered_log(i,j) = weights(:)' * window_vec; end end % 6. 反变换并恢复图像 filtered_image = exp(filtered_log); % 指数反变换 filtered_image = uint8(filtered_image); % 转回uint8显示 % 7. 显示结果对比 figure; subplot(121); imshow(sar_image); title('原始SAR图像(含相干斑)'); subplot(122); imshow(filtered_image); title('LMS滤波后(去噪)'); 以上代码用于SAR LMS MATLAB 程序对吗
最新发布
07-30
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值