HDU - 6570 - Wave(暴力)
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.
InputThe 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.OutputPrint the length of the longest "wave" subseries.Sample Input
5 3 1 2 1 3 2
Sample Output
4
把任意两个数的位置存一下 然后暴力枚举进行依次存放即可
代码:
#include<cstdio> #include<iostream> #include<algorithm> #include<cstring> #include<queue> #include<stack> #include<set> #include<map> #include<vector> #include<cmath> const int maxn=1e5+5; typedef long long ll; using namespace std; vector<int>vec[105]; int main() { int n,c; cin>>n>>c; int x; for(int t=1;t<=n;t++) { scanf("%d",&x); vec[x].push_back(t); } int ans=0; for(int t=1;t<=c;t++) { for(int j=1;j<=c;j++) { if(t==j)continue; int s1=vec[t].size(); int s2=vec[j].size(); int st1=0,st2=0; int temp=0; int sum=0; for(;;) { while(st1<s1&&vec[t][st1]<temp) { st1++; } if(st1==s1) { break; } temp=vec[t][st1]; sum++; while(st2<s2&&vec[j][st2]<temp) { st2++; } if(st2==s2) { break; } sum++; temp=vec[j][st2]; } ans=max(ans,sum); } } printf("%d\n",ans); return 0; }
-------------------------------------------
个性签名:独学而无友,则孤陋而寡闻。做一个灵魂有趣的人!
如果觉得这篇文章对你有小小的帮助的话,记得在右下角点个“推荐”哦,博主在此感谢!
万水千山总是情,打赏一分行不行,所以如果你心情还比较高兴,也是可以扫码打赏博主,哈哈哈(っ•̀ω•́)っ✎⁾⁾!