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;
	}
}

版权声明:本文为博主原创文章,未经博主允许不得转载。

时间: 2024-08-28 15:33:58

codeforces 558B Amr and The Large Array-yy的相关文章

codeforces 558B. Amr and The Large Array 解题报告

题目链接:http://codeforces.com/problemset/problem/558/B 题目意思:给出一个序列,然后找出出现次数最多,但区间占用长度最短的区间左右值. 由于是边读入边比较,因此问题最关键的是,记录每个数第一次出现的位置,即左值.因为要保证次数是出现最多,因此需要一个cnt[]数组来记录出现次数.然后当最多出现次数与当前cnt[x]次数相同时,要选择区间较短的,再更新左右区间值. 赛中短路竟然想不出来~~~泪啊~~泪啊- >_< 1 #include <io

codeforces 558B Amr and The Large Array

这个B不难.......主要就是题意和细节吧 题意是找到出现次数最多的数的左右端点值,,,一样多的话找区间最小的,,,,一样长的话找最左边的...... 改的有点乱,,,,慢慢改好的,,,,, #include<stdio.h> #include<string.h> #include <algorithm> #include <bits/stdc++.h> using namespace std; struct node { int c,b; }a[1000

Codeforces 558B Amr and The Large Array 数组美丽值

题意:给一个数组,记数组中出现次数最多的元素出现的次数为这个数组的美丽值,求这个数组长度最短的子数组(要连续),使得该子数组的美丽值与原数组美丽值相等.要求输出子数组的起始和结束位置下标(从1开始). 也是个水题.每个数最大才10^6,用hash存储每个数出现的次数即可.注意有可能有多个不同的元素出现的次数都相等且为最大,需要一一判断.遍历数组的时候可以用两个值 l[i],r[i] 维护每个数最左出现的位置和最右出现的位置.这样可以直接计算长度. #include <iostream> #in

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. Amr doesn't care about anything in the array except the beauty of it. The beauty of the array is defined to be the maximum number of times that some

暴力 + 贪心 --- Codeforces 558C : Amr and Chemistry

C. Amr and Chemistry Problem's Link: http://codeforces.com/problemset/problem/558/C Mean: 给出n个数,让你通过下面两种操作,把它们转换为同一个数.求最少的操作数. 1.ai = ai*2 2.ai = ai/2 (向下取整) analyse: 基本思路:首先枚举出每个数能够到达的数字并且记录下到达该数组需要的步数,然后从到达次数为n次的数字中选择步数最小的即为答案. 对于一个数字Ai,它可以变换得到的数字可

Codeforces 558C Amr and Chemistry(数论+位运算)

C. Amr and Chemistry time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Amr loves Chemistry, and specially doing experiments. He is preparing for a new interesting experiment. Amr has n differ

CodeForces Round #179 (295A) - Greg and Array

题目链接:http://codeforces.com/problemset/problem/295/A 我的做法,两次线段树 #include <cstdio> #include <cstring> const int N = 100005; long long sumv[N * 3]; long long add[N * 3]; long long a[N]; struct opera { int l, r; long long d; } op[N]; void pushdown

codeforces 507B. Amr and Pins 解题报告

题目链接:http://codeforces.com/problemset/problem/507/B 题目意思:给出圆的半径,以及圆心坐标和最终圆心要到达的坐标位置.问最少步数是多少.移动见下图.(通过圆上的边固定转动点,然后转动任意位置,圆心就会移动了,这个还是直接看图吧) 解题的思路就是,两点之间,距离最短啦----要想得到最少步数,我们需要保证圆心在这条连线上移动,每次转动的角度是180度,而每步移动的距离是2r,直到两个圆交叉,要注意最后一步转动的角度可能会小于180度.最后就是注意精

CodeForces 558C Amr and Chemistry (位运算,数论,规律,枚举)

Codeforces 558C 题意:给n个数字,对每个数字可以进行两种操作:num*2与num/2(向下取整),求:让n个数相等最少需要操作多少次. 分析: 计算每个数的二进制公共前缀. 枚举法亦可. /* *Author : Flint_x *Created Time : 2015-07-22 12:33:11 *File name : whust2_L.cpp */ #include<iostream> #include<sstream> #include<fstrea