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<bits/stdc++.h>
using namespace std;
const int N=1000+10;
int a[N];
int main()
{
int n,i,j,x;
while(~scanf("%d",&n))
{
x=0;
for(i=0;i<n;i++)
scanf("%d",&a[i]);
sort(a,a+n);
int k=1;
for(i=0;i<n-1;i++)
{
for(j=k;j<n;j++)
if(a[j]>a[i])
{
k=j+1;//下次直接从k开始找,避免重复问题;
x++;
break;
}
}
printf("%d\n",x);
}
return 0;
}

CF651B-Beautiful Paintings的更多相关文章

  1. codeforces 651B Beautiful Paintings

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

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

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

  3. Codeforces 651 B. Beautiful Paintings

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

  4. codeforces 651B B. Beautiful Paintings

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

  5. 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 ...

  6. Beautiful Paintings

    There are n pictures delivered for the new exhibition. The i-th painting has beauty ai. We know that ...

  7. B. Beautiful Paintings

    time limit per test 1 second memory limit per test 256 megabytes input standard input output standar ...

  8. CodeForces 651B Beautiful Paintings 贪心

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

  9. 【CodeForces 651B】Beautiful Paintings 排序+贪心

    题目大意: 给定集合,对于任意一个的排列,记,求. 很明显每次搞出一个长度为的最长上升序列,然后把元素给删掉,答案增加. 直接暴力需要. 但是可以进行优化. 设有个,将个数从小到大排序,记为长度为的数 ...

  10. codeforce 651B Beautiful Paintings

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

随机推荐

  1. Java迭代器的用法【转】

    迭代器(Iterator) 迭代器是一种设计模式,它是一个对象,它可以遍历并选择序列中的对象,而开发人员不需要了解该序列的底层结构.迭代器通常被称为“轻量级”对象,因为创建它的代价小. Java中的I ...

  2. PHP生成和获取XML格式数据

    在做数据接口时,我们通常要获取第三方数据接口或者给第三方提供数据接口,而这些数据格式通常是以XML或者JSON格式传输,本文将介绍如何使用PHP生成XML格式数据供第三方调用以及如何获取第三方提供的X ...

  3. 【转】android技术栈

    android技术栈-现有使用的进行一个汇总(初稿) 2017年04月24日 16:19:40 阅读数:2004 android技术栈 开发工具 Android studio 开发语言 Java 自动 ...

  4. var、符号运算、条件语句、三元(目)运算、自加和自减

    1.var  a=“hello world” a 这个变量是字符串了,对于里面的每一个字母来说,他是字节,里面有11个字节,(包括空格),字节总数用length表示 2.符号运算 + 字符串拼接 . ...

  5. 列表、margin和padding的探讨、标签的分类

    一.列表 列表分为无序列表.有序列表和自定义列表 1.无序列表   <ul></ul> 1).内部必须有子标签,<li></li> 2).ul天生自带内 ...

  6. git 配置免密上传,配置ssh key

    1.windows 打开git bash 控制台,linux 直接打开命令控制台,输入 ssh-keygen 一直enter 下一步 2.生成的文件windows 存放在c://users 路径下,l ...

  7. jQuery ajax参数后台获取不到的问题

    <script type="text/javascript"> init(); var alldate = {a : "0",b:"1&q ...

  8. 怎么用eclipse生成jar文件?eclipse导出jar介绍

    1 .我们先要增加jar需要的配置文件,选中项目的src目录,鼠标右键,选择 [New] -选择 [Folder] . 2. 输入META-INF 作为目录名称,点击[Finish] . 3. 选中刚 ...

  9. python大文件读取

    python大文件读取 https://stackoverflow.com/questions/8009882/how-to-read-a-large-file-line-by-line-in-pyt ...

  10. 如何在运行时改变App的图标

    在你完成应用程序的beta版本后,最后会有些人去帮你测试,使你去完善应用程序……或者会有投资青睐.但是如果测试人员有一种简单地方式去检查构建版本的应用程序会不会有帮助呢? 这个教程将会向你展示这些,向 ...