codeforces #345 div 2 B. Beautiful Paintings (暴力)

题目链接 题意:给出一个数列,按照最好的策略排序使得a[i+1]>a[i]的对数尽可能多,问最多的对数是多少。 思路:类似计数排序?

/* ***********************************************
Author :111qqz
Created Time :2016年03月07日 星期一 17时06分48秒
File Name :code/cf/#345/B.cpp
************************************************ */
 1#include <cstdio>
 2#include <cstring>
 3#include <iostream>
 4#include <algorithm>
 5#include <vector>
 6#include <queue>
 7#include <set>
 8#include <map>
 9#include <string>
10#include <cmath>
11#include <cstdlib>
12#include <ctime>
13#define fst first
14#define sec second
15#define lson l,m,rt<<1
16#define rson m+1,r,rt<<1|1
17#define ms(a,x) memset(a,x,sizeof(a))
18typedef long long LL;
19#define pi pair < int ,int >
20#define MP make_pair
 1using namespace std;
 2const double eps = 1E-8;
 3const int dx4[4]={1,0,0,-1};
 4const int dy4[4]={0,-1,1,0};
 5const int inf = 0x3f3f3f3f;
 6const int N=1E3+7;
 7int n ;
 8int a[N];
 9int cnt[N];
10int num[N];
11int sum[N];
12int main()
13{
14	#ifndef  ONLINE_JUDGE 
15	freopen("code/in.txt","r",stdin);
16  #endif
 1    cin>>n;
 2    ms(cnt,0);
 3    ms(num,0);
 4    ms(sum,0);
 5    for ( int i = 1 ; i <= n ; i++)
 6    {
 7	cin>>a[i];
 8	cnt[a[i]]++;
 9    }
10    if (n==1)
11    {
12	puts("0");
13	return 0 ;
14    }
15    if (n==2)
16    {
17	if (a[1]==a[2])
18	{
19	    puts("0");
20	}
21	else
22	{
23	    puts("1");
24	}
25	return 0;
26    }
1    int mx = -1;
2    for ( int i = 1 ; i <= 1000 ; i++)
3    {
4	num[cnt[i]]++;
5	mx = max(mx,cnt[i]);
6    }
1    for ( int i = mx ; i >= 1 ; i --)
2    {
3	sum[i] = sum[i+1]+num[i];
4    }
1    int ans = 0 ;
2    for ( int i = 1 ; i <= mx ; i++)
3    {
4	ans +=sum[i]-1;
5//	cout<<"sum[i]:"<<sum[i]<<endl;
6    }
7    cout<<ans<<endl;
1  #ifndef ONLINE_JUDGE  
2  fclose(stdin);
3  #endif
4    return 0;
5}