C题 如果一个数字出现两次及以上,那么它可以放在某个数的两侧,则答案数+1;
如果只出现一次,那么答案数是+1/2(上取整)
比如 1 2 3 可以得到 1 3 2
#include<bits/stdc++.h>
using namespace std;
void solve()
{
int n;
cin>>n;
map<int,int>mp;
for(int i=1;i<=n;i++){
int temp;
cin>>temp;
mp[temp]++;
}
int res=0;
int ans=0;
for(auto eg:mp)
{
if(eg.second>1)res++;
else ans++;
}
cout<<res+(ans+1)/2<<"\n";
}
int main()
{
ios::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr);
int t;
cin>>t;
while(t--)
{
solve();
}
}