CF 558B Amr and The Large Array(暴力法)

B. Amr and The Large Array
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

Amr has got a large array of size n. Amr doesn't like large arrays so he intends to make it smaller.

Amr doesn't care about anything in the array except the beauty of it. The beauty of the array is defined to be the maximum number of times that some number occurs in this array. He wants to choose the smallest subsegment of this array such that the beauty of it will be the same as the original array.

Help Amr by choosing the smallest subsegment possible.

Input

The first line contains one number n (1 ≤ n ≤ 105), the size of the array.

The second line contains n integers ai (1 ≤ ai ≤ 106), representing elements of the array.

Output

Output two integers l, r (1 ≤ l ≤ r ≤ n), the beginning and the end of the subsegment chosen respectively.

If there are several possible answers you may output any of them.

Sample test(s)
input
5
1 1 2 2 1
output
1 5
input
5
1 2 2 3 1
output
2 3
input
6
1 2 2 1 1 2
output
1 5
Note

A subsegment B of an array A from l to r is an array of size r - l + 1 where Bi = Al + i - 1 for all 1 ≤ i ≤ r - l + 1

有一个序列,找出包含它的出现次数最多的那个数的所有的那些次中最小的序列。就是找出它的众数,子序列的众数出现的次数和原序列的次数一样,

求最短的这个子序列。

当时眼瞎,没看到最短这个条件。

AC代码:

#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <algorithm>
using namespace std;
#define maxn 100005
#define maxa 1000005
struct count_a
{
	int value, min, max;
	count_a()
	{
		value = 0; min = 0; max = 0;
	}
};
count_a cnt[maxa];
int num[maxn];
int main()
{
	//取最短区间
	int n;
	int max_num = 0, last_value = 0, last_dis = maxn;
	scanf("%d", &n);
	for (int i = 1; i <= n; i++)
	{
		scanf("%d", &num[i]);
		cnt[num[i]].value++;
		if (cnt[num[i]].min != 0)
		{ cnt[num[i]].max = i; }
		else
		{
			cnt[num[i]].min = i;
			cnt[num[i]].max = i;
		}
		if (cnt[num[i]].value > last_value)
		{
			last_value = cnt[num[i]].value;
			max_num = num[i];
			last_dis = cnt[num[i]].max - cnt[num[i]].min;
		}
		else if (cnt[num[i]].value == last_value)
		{
			if (cnt[num[i]].max - cnt[num[i]].min < last_dis)
			{
				last_value = cnt[num[i]].value;
				max_num = num[i];
				last_dis = cnt[num[i]].max - cnt[num[i]].min;
			}
		}
	}
	printf("%d %d", cnt[max_num].min, cnt[max_num].max);
//	system("pause");
	return 0;
}


内容概要:本文围绕“组稀疏信号去噪”展开,深入研究了基于非凸正则化与凸优化的信号处理方,并提供了完整的Matlab代码实现。文章系统阐述了如何通过引入非凸正则项克服传统稀疏恢复方的局限性,从而在语音增强等实际应用中实现更优的去噪性能。研究采用组稀疏建模范式,将信号按子带或时频块进行分组,以更好地保留信号的结构性特征。文中详细构建了相应的数学模型,将原始优化问题转化为可通过凸优化技术求解的形式,并设计了高效的求解算。通过全面的仿真实验,验证了该方在提升信噪比和改善语音主观质量方面的显著优势,尤其在强噪声环境下表现出更强的鲁棒性。; 适合人群:具备一定信号处理理论基础和Matlab编程能力的研究生、科研人员,以及从事语音增强、音频处理、通信工程等相关领域的技术研发人员。; 使用场景及目标:①应用于语音通信系统、智能助听设备、语音识别前端预处理等对语音清晰度要求高的场景,有效提升嘈杂环境下的语音可懂度;②为科研工作者提供一个将非凸正则化理论与凸优化算相结合的完整研究范例,促进先进信号恢复算在实际工程系统中的转化与应用。; 阅读建议:建议读者结合提供的Matlab代码,深入剖析算实现的核心步骤,重点关注目标函数的设计理念、非凸正则项的选取依据以及优化求解器的具体实现;同时,鼓励通过调整算参数或在不同类型的噪声环境中进行测试,以探究算的性能边界和鲁棒性特征。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值