题目链接:http://codeforces.com/problemset/problem/558/B

题目意思:给出一个序列,然后找出出现次数最多,但区间占用长度最短的区间左右值。

  由于是边读入边比较,因此问题最关键的是,记录每个数第一次出现的位置,即左值。因为要保证次数是出现最多,因此需要一个cnt[]数组来记录出现次数。然后当最多出现次数与当前cnt[x]次数相同时,要选择区间较短的,再更新左右区间值。

  赛中短路竟然想不出来~~~泪啊~~泪啊- >_<

  

 #include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
using namespace std; const int maxn = 1e6 + ;
int cnt[maxn];
int pl[maxn]; // 记录每个数第一次出现的位置 int main()
{
#ifndef ONLINE_JUDGE
freopen("in.txt", "r", stdin);
#endif // ONLINE_JUDGE int n, a;
while (scanf("%d", &n) != EOF) {
memset(cnt, , sizeof(cnt));
memset(pl, , sizeof(pl));
int max_cnt = ;
int min_dis = ;
int l = , r = ; for (int i = ; i < n; i++) {
scanf("%d", &a); if (!cnt[a]) {
pl[a] = i;
}
cnt[a]++; if (max_cnt < cnt[a]) {
max_cnt = cnt[a];
l = pl[a], r = i;
min_dis = i - tl;
}
if (max_cnt == cnt[a] && i-pl[a] < min_dis) {
min_dis = i - pl[a];
l = pl[a];
r = i;
}
}
printf("%d %d\n", l+, r+);
}
return ;
}

codeforces 558B. Amr and The Large Array 解题报告的更多相关文章

  1. Codeforces 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 st ...

  2. codeforces 558B Amr and The Large Array-yy

    题意:有一个数组.如今要削减它的尺寸.数组中同样元素的个数的最大值为数组的魅力值,要求削减后魅力值不能降低,同一时候要尽可能的把尺寸减到最小 分析:水题,主要是不要想复杂了.还有就是沉下心来做 代码: ...

  3. codeforces 558B B. Amr and The Large Array(水题)

    题目链接: B. Amr and The Large Array time limit per test 1 second memory limit per test 256 megabytes in ...

  4. Codeforces Round #312 (Div. 2)B. Amr and The Large Array 暴力

    B. Amr and The Large Array Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contes ...

  5. B. Amr and The Large Array(Codeforces Round #312 (Div. 2)+找出现次数最多且区间最小)

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

  6. 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 st ...

  7. 【LeetCode】697. Degree of an Array 解题报告

    [LeetCode]697. Degree of an Array 解题报告 标签(空格分隔): LeetCode 题目地址:https://leetcode.com/problems/degree- ...

  8. 【LeetCode】153. Find Minimum in Rotated Sorted Array 解题报告(Python)

    [LeetCode]153. Find Minimum in Rotated Sorted Array 解题报告(Python) 标签: LeetCode 题目地址:https://leetcode. ...

  9. 【36.86%】【codeforces 558B】Amr and The Large Array

    time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard ou ...

随机推荐

  1. LINUX下搭建VPN

    一.准备 需要 dkms-2.0.17.5-1.noarch.rpm.ppp-2.4.5-33.0.rhel6.x86_64.rpm.pptpd-1.4.0-1.el6.x86_64.rpm,并依次安 ...

  2. ExtJS请求验证方法

    //登录连接数据库验证 function loginCheck() { var UserName = Ext.getCmp("UserName").getValue(); var ...

  3. Linux运维初级教程(三)文件及目录权限

    文件类型 -代表普通文件,d代表目录,l代表链接文件,b或c代表设备. 第二至九个字符代表权限,分别为所有者权限.所属组权限.其他账户权限 修改权限用chmod u用户 g组 o其他用户 a所有人 c ...

  4. HTML中head头结构

    HTML head 头部分的标签.元素有很多,涉及到浏览器对网页的渲染,SEO等等,而各个浏览器内核以及各个国内浏览器厂商都有些自己的标签元素,这就造成了很多差异性.移动互联网时代,head 头部结构 ...

  5. assign与weak区别(面试)

    weak 比 assign 多了一个功能就是当属性所指向的对象消失的时候(也就是内存引用计数为0)会自动赋值为 nil ,这样再向 weak 修饰的属性发送消息就不会导致野指针操作crash. 可能不 ...

  6. 决策树-预测隐形眼镜类型 (ID3算法,C4.5算法,CART算法,GINI指数,剪枝,随机森林)

    1. 1.问题的引入 2.一个实例 3.基本概念 4.ID3 5.C4.5 6.CART 7.随机森林 2. 我们应该设计什么的算法,使得计算机对贷款申请人员的申请信息自动进行分类,以决定能否贷款? ...

  7. Ubuntu 12 修改环境变量

    Ubuntu Linux系统包含两类环境变量:系统环境变量和用户环境变量.系统环境变量对所有系统用户都有效,用户环境变量仅仅对当前的用户有效. 修改用户环境变量 用户环境变量通常被存储在下面的文件中: ...

  8. servlet之filter过滤器

    1.Servlet 过滤器有以下目的 在客户端的请求访问后端资源之前,拦截这些请求. 在服务器的响应发送回客户端之前,处理这些响应. 2.Filter接口 1.每一个过滤器都需直接或间接继承Filte ...

  9. maven之ubutu安装

    1.下载地址:http://maven.apache.org/download.cgi 2.安装 将下载后的文件解压到你指定的文件即可,命令如下: tar -xzvf apache-maven-3.0 ...

  10. 02快速学习ExtJs之---第一个HelloWord!

    这篇主要讲部署下ExtJS开发环境,以及搭建项目.我们使用ExtJs官方提供的Sencha Cmd来搭建 1.搭建项目 1.下载官方的Sencha Cmd工具,安装. 2..Window用户进入到命令 ...