B. Beautiful Paintings
time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

standard output

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.

Examples
input
5
20 30 10 50 40
output
4
input
4
200 100 100 200
output
2
Note

In the first sample, the optimal order is: 10, 20, 30, 40, 50.

In the second sample, the optimal order is: 100, 200, 100, 200.

题意:在一个序列中,当遇到递增的数时,会觉得开心,现在给一组数,问可以开心几次

分析:求出这个序列中总共有多少个上升的序列,并且没个上升序列中有多少个元素

题解:先将序列从小到大排序,记录所有重复出现的数的次数,去掉出现次数最多的求剩下的数的和即可

#include<stdio.h>
#include<string.h>
#include<string>
#include<math.h>
#include<algorithm>
#define LL long long
#define PI atan(1.0)*4
#define DD double
#define MAX 3000
#define mod 100
#define dian 1.000000011
#define INF 0x3f3f3f
using namespace std;
int s[MAX];
int vis[MAX];
int main()
{
int n,m,j,i,t,k;
while(scanf("%d",&n)!=EOF)
{
for(i=0;i<n;i++)
scanf("%d",&s[i]);
sort(s,s+n);
for(i=0;i<=n;i++)
vis[i]=1;
k=0;
for(i=0;i<n;i++)
{
if(s[i]==s[i+1])
vis[k]++;
else
k++;
}
int sum=0;
sort(vis,vis+k);
for(i=0;i<k-1;i++)
sum+=vis[i];
printf("%d\n",sum);
}
return 0;
}

  

codeforces 651B Beautiful Paintings的更多相关文章

  1. CodeForces 651B Beautiful Paintings 贪心

    A. Joysticks time limit per test 1 second memory limit per test 256 megabytes input standard input o ...

  2. Codeforces 651B Beautiful Paintings【贪心】

    题意: 给定序列,重新排序,使严格上升的子序列最多.求这些子序列总长度. 分析: 贪心,统计每个元素出现次数,每次从剩余的小的开始抽到大的,直到不再剩余元素. 代码: #include<iost ...

  3. codeforce 651B Beautiful Paintings

    题意:后一个比前一个大就加一,问最大次数. #include<cstdio> #include<cstring> #include<algorithm> #incl ...

  4. [刷题codeforces]651B/651A

    651B Beautiful Paintings 651A Joysticks 点击可查看原题 651B是一个排序题,只不过多了一步去重然后记录个数.每次筛一层,直到全为0.从这个题里学到一个正确姿势 ...

  5. codeforces 651B B. Beautiful Paintings

    B. Beautiful Paintings time limit per test 1 second memory limit per test 256 megabytes input standa ...

  6. Codeforces Round #345 (Div. 2) B. Beautiful Paintings 暴力

    B. Beautiful Paintings 题目连接: http://www.codeforces.com/contest/651/problem/B Description There are n ...

  7. Codeforces 651 B. Beautiful Paintings

    B. Beautiful Paintings   time limit per test 1 second memory limit per test 256 megabytes input stan ...

  8. Codeforces Round #345 (Div. 2)——B. Beautiful Paintings(贪心求上升序列个数)

    B. Beautiful Paintings time limit per test 1 second memory limit per test 256 megabytes input standa ...

  9. Codeforces 55D Beautiful Number

    Codeforces 55D Beautiful Number a positive integer number is beautiful if and only if it is divisibl ...

随机推荐

  1. ASCII 字符代码表

  2. R: count number of distinct values in a vector

    numbers <- c(4,23,4,23,5,43,54,56,657,67,67,435,         453,435,324,34,456,56,567,65,34,435) a & ...

  3. GridView表头排序方法设置

    1.效果图 2.前台代码 说明:红色代码为核心代码 <asp:GridView ID="gvData" runat="server" AutoGenera ...

  4. Android之 学习路线

    第一阶段:Java面向对象编程 1.Java基本数据类型与表达式,分支循环.  2.String和StringBuffer的使用.正则表达式.  3.面向对象的抽象,封装,继承,多态,类与对象,对象初 ...

  5. 深入学习Oracle分区表及分区索引

    关于分区表和分区索引(About Partitioned Tables and Indexes)对于10gR2而言,基本上可以分成几类: •       Range(范围)分区 •       Has ...

  6. 查看ORACLE执行计划的几种常用方法

    SQL的执行计划实际代表了目标SQL在Oracle数据库内部的具体执行步骤,作为调优,只有知道了优化器选择的执行计划是否为当前情形下最优的执行计划,才能够知道下一步往什么方向. 执行计划的定义:执行目 ...

  7. MySQL基础之第13章 MySQL函数

    13.1.数学函数 随机数可能会用到,其他基本无视. 13.2.字符串函数 重点CONCAT(S1,S2….) 13.3.日期和时间函数 一.MySQL 获得当前日期时间 函数 1.1 获得当前日期+ ...

  8. Ch04-文字列表的设计

    Ch04: 文字列表的设计 4.1 编号列表 语法: <OL> <li>编号1 <li>编号2 ...... </OL> 属性: 编号类型:type=1 ...

  9. Linux系统性能监控

    系统的性能指标主要包括CPU.内存.磁盘I/O.网络几个方面. 1. CPU性能 (1)利用vmstat命令监控系统CPU 该命令可以显示关于系统各种资源之间相关性能的简要信息,这里我们主要用它来看C ...

  10. HDU 5742 It's All In The Mind

    It's All In The Mind Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Oth ...