codeforces 558B Amr and The Large Array-yy
题意:有一个数组。如今要削减它的尺寸。数组中同样元素的个数的最大值为数组的魅力值,要求削减后魅力值不能降低,同一时候要尽可能的把尺寸减到最小
分析:水题,主要是不要想复杂了。还有就是沉下心来做
代码:
#include<iostream>
#include<cstring>
#include<algorithm>
#define INF 1000000007
#define max(a,b) a>b?a:b
using namespace std;
int n,a[100010];
int tot[1000010];
int l[1000010],r[1000010];
int main()
{
while(cin>>n){
memset(tot,0,sizeof(tot));
memset(l,0,sizeof(l));
memset(r,0,sizeof(r));
int mx=-1;
for(int i=1;i<=n;i++){
cin>>a[i];
if(tot[a[i]]==0) l[a[i]]=i,r[a[i]]=i;
else r[a[i]]=i;
tot[a[i]]++;
mx=max(mx,tot[a[i]]);
}
int mi=INF;
int ans;
for(int i=1;i<=n;i++){
if(tot[a[i]]==mx){
int tmp=r[a[i]]-l[a[i]];
if(mi>tmp){
mi=tmp;
ans=a[i];
}
}
}
cout<<l[ans]<<" "<<r[ans]<<endl;
}
}
codeforces 558B Amr and The Large Array-yy的更多相关文章
- 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 解题报告
题目链接:http://codeforces.com/problemset/problem/558/B 题目意思:给出一个序列,然后找出出现次数最多,但区间占用长度最短的区间左右值. 由于是边读入边比 ...
- 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 ...
- 【36.86%】【codeforces 558B】Amr and The Large Array
time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard ou ...
- Codeforces Round #312 (Div. 2) B.Amr and The Large Array
Amr has got a large array of size n. Amr doesn't like large arrays so he intends to make it smaller. ...
- CodeForces 558B
Description Amr has got a large array of size n. Amr doesn't like large arrays so he intends to make ...
随机推荐
- windows系统 安装MongoDB
1.下载 官网下载地址:https://www.mongodb.com/download-center#community 2.配置MongoDB a.在e:\MongoDB(可随意起)下面建一个da ...
- wpf tooltip 样式自定义
<Style BasedOn="{StaticResource {x:Type ToolTip}}" TargetType="ToolTip"> & ...
- SQL Server 2000中查询表名,列名及字段类型
经常碰到一些忘记表名称的情况,此时只记得个大概,此时可通过查询系统表Sysobjects找到所要的表名,如要查找包含用户的表名,可通过以下SQL语句实现, Select * From sysobjec ...
- Asp.Net MVC Razor视图引擎与My97DatePicker插件的结合
using System; using System.Collections.Generic; using System.Runtime.CompilerServices; using System. ...
- Java 中常见数据类型的相互转换
1.将String 转化成 long , 转化成 double String 转化成 long : long i = Long.parseLong(String s); 或 long i = L ...
- 【原创】记一次MySQL大表高并发写入引发CPU飙升的排障过程
目录 一.故障现象... 1 二.初步分析... 2 三.排障过程... 2 1.排查是否QPS或insert并发请求上升导致问题发生... 2 2.排查是否锁资源等待或block导致了insert变 ...
- [leetcode tree]102. Binary Tree Level Order Traversal
Given a binary tree, return the level order traversal of its nodes' values. (ie, from left to right, ...
- iOS 11开发教程(十)iOS11无线连接手机真机测试
iOS 11开发教程(十)iOS11无线连接手机真机测试 在Xcode 9.0中,已经可以通过无线连接手机进行真机测试了.具体的操作步骤如下: (1)首先需要使用数据线将手机连接到苹果电脑上. (2) ...
- Javascript中call方法和apply方法用法和区别
第一次在博客园上面写博客,知识因为看书的时候发现了一些有意思的知识,顺便查了一下资料,就发到博客上来了,希望对大家有点帮助. 连续几天阅读<javascript高级程序设计>这本书了,逐渐 ...
- nginx + uswgi +django
适合ubuntu 系统,不只是树莓派 安装必要软件 pt-get install build-essential psmisc apt-get install python-dev libxml2 l ...