• CodeForces 651B


    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 }
  • 相关阅读:
    基于emWin的WAV,MP3软解软件播放器,带类似千千静听频谱,含uCOS-III和FreeRTOS两个版本
    [Linux-CentOS7]yum清华源CentOS7
    [Python]random生成随机6位验证码
    [Python]公司接口返回值规范
    [MacOS]Chrome 强制刷新
    Mybatis的XML中数字不为空的判断
    康师傅JVM:执行引擎(十二)
    Qt 随机颜色的生成
    Qt QVector常见使用方法
    Qt 判断文件是否存在
  • 原文地址:https://www.cnblogs.com/Aa1039510121/p/5687701.html
Copyright © 2020-2023  润新知