codeforces 558B. Amr and The Large Array 解题报告
题目链接: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 解题报告的更多相关文章
- 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 ...
- codeforces 558B Amr and The Large Array-yy
题意:有一个数组.如今要削减它的尺寸.数组中同样元素的个数的最大值为数组的魅力值,要求削减后魅力值不能降低,同一时候要尽可能的把尺寸减到最小 分析:水题,主要是不要想复杂了.还有就是沉下心来做 代码: ...
- 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 ...
- 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 ...
- 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 ...
- 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 ...
- 【LeetCode】697. Degree of an Array 解题报告
[LeetCode]697. Degree of an Array 解题报告 标签(空格分隔): LeetCode 题目地址:https://leetcode.com/problems/degree- ...
- 【LeetCode】153. Find Minimum in Rotated Sorted Array 解题报告(Python)
[LeetCode]153. Find Minimum in Rotated Sorted Array 解题报告(Python) 标签: LeetCode 题目地址:https://leetcode. ...
- 【36.86%】【codeforces 558B】Amr and The Large Array
time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard ou ...
随机推荐
- 10条PHP编程习惯助你找工作
过去的几周对我来说是一段相当复杂的经历.我们公司进行了大裁员,我是其中之一,但却体验到了其中的乐 趣.我从来没有被开除过,所以很难不去想得太多.我开始浏览招聘板块,一个全职PHP程序员的职位很吸引人, ...
- linq学习
最全的linq学习文章: http://www.cnblogs.com/heyuquan/p/Linq-to-Objects.html
- 【转载】VC维的来龙去脉
本文转载自 火光摇曳 原文链接:VC维的来龙去脉 目录: 说说历史 Hoeffding不等式 Connection to Learning 学习可行的两个核心条件 Effective Number o ...
- github及其他记录
http://mvnrepository.com/artifact/org.jdom/jdom/1.1.3 https://github.com/open-power-workgroup/Hospit ...
- HDOJ 4750 Count The Pairs
按边长从小到大排序...再逐个加入(就像MST一样)最先联通的点之间最长路径中的最小值就是新加入的边的长.... Count The Pairs Time Limit: 20000/10000 MS ...
- PHP简易聊天室&调试问题
在进入login.php程序之后 <?php error_reporting(E_ALL^E_NOTICE); session_start(); //装载Session库,一定要放在首行 $u ...
- plink远程连接服务器进行编译
脚本命令: echo y|D:\remote_link\plink -l user -pw password 172.16.0.101 "export LANG=en_US;cd / ...
- C++ GET UTF-8网页编码转换
string UTF8ToGBK(const std::string& strUTF8) //GBKתUTF-8 { int le ...
- Android应用签名
http://www.cnblogs.com/ghj1976/archive/2011/07/18/2109381.html 为了要签名? 开发Android的人这么多,完全有可能大家都把类名,包名起 ...
- NumPy的详细教程
原文 http://blog.csdn.net/lsjseu/article/details/20359201 主题 NumPy 先决条件 在阅读这个教程之前,你多少需要知道点python.如果你想 ...