题目意思: 给你一个为环的序列n,这个序列有一个特殊的地方:就是如果有相邻元素相等他就会立马删除其中一个元素(第一个和最后一个相邻)。 然后你每次可以删除一个元素,问你能删除的最多的操作数是多少。
题目思路:
我们可以发现如果有一个元素只有一个数的话,那么可以通过以这个元素为中心不断删除n次。
首先如果元素种类为2 的话,肯定结果就是,
当环中至少含有三种不同的元素 假设是a,b,c(三种),然后我们以任意一个元素为中心
,假设是b然后删除他周围的能删的数,直到不能删了或者有一个数存在一个。
如果是不能以b为中心去删了,那么因为至少含有三种元素,那么一定会有一个元素只有一个。、
那么无论如果都会有存在一个元素只存在一个的情况。
所以可以一直删直到n次
所以就是如果元素种类大于等于3就是n,否则为n/2+1;
/**
* ┏┓ ┏┓+ +
* ┏┛┻━━━┛┻┓ + +
* ┃ ┃
* ┃ ━ ┃ ++ + + +
* ████━████+
* ◥██◤ ◥██◤ +
* ┃ ┻ ┃
* ┃ ┃ + +
* ┗━┓ ┏━┛
* ┃ ┃ + + + +Code is far away from
* ┃ ┃ + bug with the animal protecting
* ┃ ┗━━━┓ 神兽保佑,代码无bug
* ┃ ┣┓
* ┃ ┏┛
* ┗┓┓┏━┳┓┏┛ + + + +
* ┃┫┫ ┃┫┫
* ┗┻┛ ┗┻┛+ + + +
*/
#include<cstdio>
#include <iostream>
#include <algorithm>
#include <string.h>
#include <string>
#include <math.h>
#include<vector>
#include<queue>
#include<map>
#define sc_int(x) scanf("%d", &x)
#define sc_ll(x) scanf("%lld", &x)
#define pr_ll(x) printf("%lld", x)
#define pr_ll_n(x) printf("%lld\n", x)
#define pr_int_n(x) printf("%d\n", x)
#define ll long long
using namespace std;
const int N=1000000+100;
int n ,m,h;
ll s[N];
int main()
{
int t;
sc_int(t);
while(t--)
{
map<int,int>q;
cin>>n;
int res=0;
for(int i =1;i<=n;i++)
{
cin>>s[i];
if(!q[s[i]]){
q[s[i]]=1;
res++;
}
}
if(res>=3)cout<<n<<endl;
else cout<<n/2+1<<endl;
}
return 0;
}