http://codeforces.com/contest/651/problem/B
给n个数,问怎么排列重组后,能找出最多的 合法对
合法对的意思是: ai +1 > ai.
n=1000,
数的大小也只有1000
直接排序n^2无脑暴力模拟这个过程:
把数据映射到hash数组,每次遍历hash数组,这样的遍历一定是按从小到大的,那么每次得到一个 递增序列,他的长度-1就是我们要求的答案。累加
#include <cstdio>
#include <cmath>
#include <cstring>
#include <string>
#include <algorithm>
#include <queue>
#include <map>
#include <set>
#include <vector>
#include <iostream>
using namespace std;
const double pi=acos(-1.0);
double eps=0.000001;
int vis[1005];
int main()
{
int n;
cin>>n;
int i,j,tmp;
for (i=1;i<=n;i++)
{
scanf("%d",&tmp);
vis[tmp]++;
}
int maxx=0;
for (i=1;i<=1000;i++)
{
int cun=0;
for (j=1;j<=1000;j++)
{
if (vis[j])
{
vis[j]--;
cun++;
}
}
if (cun>0)
maxx+=cun-1;
}
printf ("%d\n",maxx);
return 0;
}