cf,,,,

​
#include<iostream>
#include<cstdio>
#include<cstring> 
using namespace std;
const int mxn = 2e5+5;
int cnt[mxn],b[mxn],a[mxn],a2[mxn];
int len,k,n,ans;
int main()
{
	int t;
	scanf("%d",&t);
	while(t--)
	{
		memset(cnt,0,sizeof(cnt));
		len=k=0;  
        
		scanf("%d",&n);
		for(int i=1;i<=n;i++)
		{
			scanf("%d",&a[i]);  //读入序列a
			if(a[i]!=a[i-1])
			{  //压缩序列a2[]
				k++;
				a2[k]=a[i];
			}
		}
        
		for(int i=1;i<=k;i++)
		{
			if(!cnt[a2[i]])
			{    //特判第一次出现
				if(i>1)  //不在开头,左侧有数组,划分段数++
					cnt[a2[i]]++;   //第一次出现过了 
			
				len++;   //第一次出现则加入最终的答案筛选数组;
				b[len]=a2[i];
			}
			
			if(i<k)  //不在结尾,划分段数++;***如开头:它不在结尾***** 
				cnt[a2[i]]++;        //若非第一次出现,之前第一次出现已经加过来 ,不用b[len] 
		}
		
    
		ans=cnt[b[1]];          //cnt:划分段数  b:筛选数组 
		for(int i=2;i<=len;i++)
		{
			ans=ans<cnt[b[i]] ?ans:cnt[b[i]];
		}
		printf("%d\n",ans);
	}
	return 0;
} 

​

C

C. Sequence Transformation

time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

standard output

You are given a sequence a�, initially consisting of n� integers.

You want to transform this sequence so that all elements in it are equal (i. e. it contains several occurrences of the same element).

To achieve this, you choose some integer x� that occurs at least once in a�, and then perform the following operation any number of times (possibly zero): choose some segment [l,r][�,�] of the sequence and remove it. But there is one exception: you are not allowed to choose a segment that contains x�. More formally, you choose some contiguous subsequence [al,al+1,…,ar][��,��+1,…,��] such that ai≠x��≠� if l≤i≤r�≤�≤�, and remove it. After removal, the numbering of elements to the right of the removed segment changes: the element that was the (r+1)(�+1)-th is now l�-th, the element that was (r+2)(�+2)-th is now (l+1)(�+1)-th, and so on (i. e. the remaining sequence just collapses).

D. Number into Sequence
  • 6
    点赞
  • 14
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值