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 ...
随机推荐
- CF451B Sort the Array 水题
Codeforces Round #258 (Div. 2) Sort the Array B. Sort the Array time limit per test 1 second memory ...
- tc 146 2 BridgeCrossing(n人过桥问题)
SRM 146 2 1000BridgeCrossing Problem Statement A well-known riddle goes like this: Four people are c ...
- Mac OS 中的 Python(和 NumPy)开发环境设置
http://www.python()tab.com/html/2013/pythonjichu_1010/582.html ()需要删除
- Swift2.1 语法指南——扩展
原档:https://developer.apple.com/library/prerelease/ios/documentation/Swift/Conceptual/Swift_Programmi ...
- php正则
PHP代码 $str = preg_replace("/(<a.*?>)(.*?)(<\/a>)/", '\1<span class="li ...
- 转一篇简易易懂的android回调的实现--->(转的)
回调机制在 Android 监听用户界面操作中的体现 本文讨论以下两个内容: 1. 回调函数 2. 回调机制在 Android框架 监听用户界面操作中的作用 一 回调函数 回调函数就是一个通过函数 ...
- iOS开发——UI进阶篇(五)通知、代理、kvo的应用和对比,购物车
一.通知 1.通知中心(NSNotificationCenter)每一个应用程序都有一个通知中心(NSNotificationCenter)实例,专门负责协助不同对象之间的消息通信任何一个对象都可以向 ...
- [RouterOS] ROS对接碧海威或PA等流控实现完美流控详细教程(附脚本全免费)
前言: 经常在群里看到不少朋友争论海蜘蛛 ROS 维盟 爱快 碧海威 流控大师 Woyos等等软路由,哪个好.实际上,网络产品是复杂的,现在的软路由功能上已经远远不是单独的路由了.每种产品都有他本身的 ...
- Android客户端的图形化拖放操作的设计实现
为什么要拖放?拖放在某些UI交互中可以简化用户操作. 拖放的步骤包括哪些?“Drag and Drop”,拖放,顾名思义,总共就分三步:1, 开始拖起来:2, 正在拖:3, 放下,进行操作:在这三步里 ...
- 如何用phpstorm编辑远程项目
背景介绍:LAMP开发是很多公司喜欢采用的技术组合,故而做php开发,使用linux环境也是很多公司的要求.本文就来介绍下如何在windows下,使用phpstorm集成开发环境,来开发放在linux ...