Wave

c++没过用G++就过了 。。。。。

Avin is studying series. A series is called "wave" if the following conditions are satisfied:
1) It contains at least two elements;
2) All elements at odd positions are the same;
3) All elements at even positions are the same;
4) Elements at odd positions are NOT the same as the elements at even positions.
You are given a series with length n. Avin asks you to find the longest "wave" subseries. A subseries is a subsequence of a series.

 

 

Input

The first line contains two numbers n, c (1 ≤ n ≤ 100, 000, 1 ≤ c ≤ 100). The second line contains n integers whose range is [1, c], which represents the series. It is guaranteed that there is always a "wave" subseries.

 

 

Output

Print the length of the longest "wave" subseries.

 

 

Sample Input

 

5 3 1 2 1 3 2

 

 

Sample Output

 

4

 

 

Source

2019CCPC-江西省赛(重现赛)- 感谢南昌大学

 

#include<stdio.h>
#include<string.h>
#include<algorithm>
using namespace std;
int a[100010];
int d[110];
int b[110];
int main()
{
	int n,c;
	scanf("%d%d",&n,&c);
	memset(b,0,sizeof(b));
	int num=0;
	for(int i=0;i<n;i++)
	{
		scanf("%d",&a[i]);
		if(!b[a[i]])
		{
			b[a[i]]=1;
			d[num++]=a[i];
		}
	}
	int ans=0;
	for(int i=0;i<num;i++)
	{
		for(int j=i+1;j<num;j++)
		{
			int t=0,v=0;
		      for(int k=0;k<n;k++)
			  {
			  	if(a[k]==d[i]&&t%2==0)
			  	{
			  		t++;
				  }
				  else if(a[k]==d[j]&&t%2==1)
				  {
				  	t++;
				  }
				  if(a[k]==d[i]&&v%2==1)
			   	    {
			   	    	v++;
					   }
					   else if(d[j]==a[k]&&v%2==0)
					   {
					   	v++;
					   }
			   }
			   ans=max(ans,max(t,v));
			   t=0,v=0;
		}
		
		
	}
	printf("%d\n",ans);
	
	return 0;
}
#include<stdio.h>
#include<vector>
#include<algorithm>
using namespace std;
typedef pair<int,int>p;
vector<p>G[110];
bool cmp(p a1,p a2)
{
	return a1.first<a2.first;
}
int main()
{
	int n,c,x;
	scanf("%d%d",&n,&c);
	for(int i=0;i<n;i++)
	{
		scanf("%d",&x);
		G[x].push_back(p(i,x));
	}
	int num=0;
	for(int i=1;i<=c;i++)
	{
		for(int j=i+1;j<=c;j++)
		{
			if(G[i].size()&&G[j].size())
			{
				vector<p>pi;
				for(int k=0;k<G[i].size();k++)
				{
					pi.push_back(G[i][k]);
				}
				for(int k=0;k<G[j].size();k++)
				{
					pi.push_back(G[j][k]); 
				}
				sort(pi.begin() ,pi.end(),cmp);
				int sum=0,flag;
				for(int k=0;k<pi.size();k++)
				{
					if(k==0) sum++,flag=pi[k].second;
					else if(pi[k].second!=flag) sum++,flag=pi[k].second;
				}
				num=max(num,sum);
			}
		}
	}
	printf("%d\n",num);
	return 0;
}

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值