标签:
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
5
20 30 10 50 40
4
4
200 100 100 200
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 }
标签:
原文地址:http://www.cnblogs.com/Aa1039510121/p/5687701.html