codeforces #312 B B. Amr and The Large Array(统计)
来源:互联网 发布:sql cast和convert 编辑:程序博客网 时间:2024/05/28 16:26
题目链接:
点击打开链接
题目大意:
给出一个序列,问如何截取连续的子序列,能够得到的子序列的出现次数最多的数的数目不变
题目分析:
记录每个数出现的次数和最左位置以及最右位置,然后判断出现次数等于最大次数的最左和最右位置间隔最小的下标即为最终答案
代码如下:
#include <iostream>#include <algorithm>#include <cstdio>#include <cstring>#define N 100007#define M 1000007using namespace std;int n;int a;int num[M];int l[M];int r[M];int maxn;int main ( ){ while ( ~scanf ( "%d" , &n )) { maxn = 0; memset ( l , -1 , sizeof (l)); memset ( r, -1 , sizeof (r)); memset ( num , 0 , sizeof ( num )); for ( int i = 1 ; i <= n ; i++ ) { scanf ( "%d" , &a ); num[a]++; if ( l[a] == -1 ) l[a] = i; r[a] = i; } for ( int i = 0 ; i < M ; i++ ) maxn = max ( maxn , num[i] ); int ans1,ans2,sum=M; for ( int i = 0 ; i < M ; i++ ) if ( num[i] == maxn ) { if ( sum > r[i]-l[i]+1) { sum = r[i]-l[i]+1; ans1 = l[i]; ans2 = r[i]; } } printf ( "%d %d\n" , ans1 , ans2 ); }}
0 0
- codeforces #312 B B. Amr and The Large Array(统计)
- Codeforces 558B Amr and The Large Array(hash)
- Codeforces 558B Amr and The Large Array
- codeforces 558B Amr and The Large Array-yy
- 【36.86%】【codeforces 558B】Amr and The Large Array
- B. Amr and The Large Array
- B-codeforces558B-Amr and The Large Array
- Codeforces Round #312 (Div. 2) B. Amr and The Large Array
- Codeforces Round #312 (Div. 2) B. Amr and The Large Array
- Codeforces Round #312 (Div. 2) B. Amr and The Large Array
- Codeforces Round #312 (Div. 2)-B. Amr and The Large Array-暴力
- Codeforces Round #312 (Div. 2) B. Amr and The Large Array
- Codeforces 558B Amr and The Large Array 数组美丽值
- CF 558B(Amr and The Large Array-计数)
- CF 558B Amr and The Large Array
- codeforce 558B Amr and The Large Array 思维题
- 【打CF,学算法——二星级】Codeforces Round #312 (Div. 2) B. Amr and The Large Array
- B. Amr and The Large Array(Codeforces Round #312 (Div. 2)+找出现次数最多且区间最小)
- srm 539
- 算法学习之一java实现选择排序
- POJ 2031
- JS高级程序设计7-函数表达式
- Ubuntu 14.04 配置android源码开发/编译环境
- codeforces #312 B B. Amr and The Large Array(统计)
- java容器类---概述
- Java基础---synchronized 详解
- centos下配置apache用户及用户组权限
- Goldengate(ora11g)配置说明
- 字符串
- cug 1179 暴力之美
- 启动Tomcat提示:指定的服务未安装
- POJ 2421