zoukankan      html  css  js  c++  java
  • 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 }
  • 相关阅读:
    HTML&CSS学习总结(一)
    PHP学习总结(一)
    二、python基础1 基本语法、流程控制
    MySQL练习题
    python自动化学习目录大全
    简单练习:Python三级菜单优化
    一、python语言简介
    网络编程与并发—批量主机管理开发
    windows安装nginx并存放静态资源
    集成xxl-job分布式任务调度平台
  • 原文地址:https://www.cnblogs.com/Aa1039510121/p/5687701.html
Copyright © 2011-2022 走看看