码迷,mamicode.com
首页 > 其他好文 > 详细

CodeForces 651B

时间:2016-07-20 11:44:26      阅读:205      评论:0      收藏:0      [点我收藏+]

标签:

Description

There are n pictures delivered for the new exhibition. The i-th painting has beauty ai. We know that a visitor becomes happy every time he passes from a painting to a more beautiful one.

We are allowed to arranged pictures in any order. What is the maximum possible number of times the visitor may become happy while passing all pictures from first to last? In other words, we are allowed to rearrange elements of a in any order. What is the maximum possible number of indices i (1 ≤ i ≤ n - 1), such that ai + 1 > ai.

Input

The first line of the input contains integer n (1 ≤ n ≤ 1000) — the number of painting.

The second line contains the sequence a1, a2, ..., an (1 ≤ ai ≤ 1000), where ai means the beauty of the i-th painting.

Output

Print one integer — the maximum possible number of neighbouring pairs, such that ai + 1 > ai, after the optimal rearrangement.

Sample Input

Input
5
20 30 10 50 40
Output
4
Input
4
200 100 100 200
Output
2
 
题解  暴力,将每个数都存在一个数组里,位序是数的大小,数组的值代表这个数的次数,最大1000,设两个循环,在里面找
 
 1 #include<iostream>
 2 #include<cstdio>
 3 #include<cmath>
 4 #include<cstring>
 5 using namespace std;
 6 int main()
 7 {
 8     int n,t,max1,i,j;
 9     int a[1005];
10     while(cin>>n)
11     {
12         memset(a,0,sizeof(a));
13         max1=1;
14         for(i=0;i<n;i++)
15         {
16             cin>>t;
17             max1=max(max1,t);
18             a[t]++;
19         }
20         int ans=0;
21         for(i=1;i<n;i++)
22         {
23             int sum=0;
24             for(j=1;j<=max1;j++)
25             {
26                 if(a[j]>0)
27                 {
28                     a[j]--;
29                     sum++;
30                 }
31             }
32             if(sum>1)
33                 ans=sum+ans-1;
34         }
35         cout<<ans<<endl;
36     }
37 }

 

CodeForces 651B

标签:

原文地址:http://www.cnblogs.com/Aa1039510121/p/5687701.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!