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
  1. 5
  2. 20 30 10 50 40
output
  1. 4
input
  1. 4
  2. 200 100 100 200
output
  1. 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.

一道如此水的题,不造怎么做了这么久,,真是无语,,学长说和又见拦截导弹差不多,于是我回去看了看,结果并没有什么收获,,但学长和我讲的时候倒是给了我点启发。。之前一直卡在元素重复问题上不造怎么解决,,原来那么水,,还是思路不行~~~

代码详解:

  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. const int N=1000+10;
  4. int a[N];
  5. int main()
  6. {
  7. int n,i,j,x;
  8. while(~scanf("%d",&n))
  9. {
  10. x=0;
  11. for(i=0;i<n;i++)
  12. scanf("%d",&a[i]);
  13. sort(a,a+n);
  14. int k=1;
  15. for(i=0;i<n-1;i++)
  16. {
  17. for(j=k;j<n;j++)
  18. if(a[j]>a[i])
  19. {
  20. k=j+1;//下次直接从k开始找,避免重复问题;
  21. x++;
  22. break;
  23. }
  24. }
  25. printf("%d\n",x);
  26. }
  27. return 0;
  28. }

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. (022)[工具软件]图片浏览 JPEGView

    JPEGView是一款小巧绿色快速的图像浏览工具,并且支持全屏或窗口模式.主页地址: https://sourceforge.net/projects/jpegview/JPEGView软件小巧,但功 ...

  2. HDU 2828 Lamp 二分图的最大匹配 模型题

    http://acm.hdu.edu.cn/showproblem.php?pid=2828 给定n个灯,m个开关,使得每栈灯亮,前提是控制这栈灯的开关的状态是其中一个.(题目应该都看得懂) 其实我想 ...

  3. 17972 Golden gun的巧克力

    17972 Golden gun的巧克力 时间限制:1000MS  内存限制:65535K提交次数:93 通过次数:13 收入:124 题型: 编程题   语言: G++;GCC;JAVA Descr ...

  4. P2142 高精度减法

    题目描述 高精度减法 输入输出格式 输入格式: 两个整数a,b(第二个可能比第一个大) 输出格式: 结果(是负数要输出负号) 输入输出样例 输入样例#1: 2 1 输出样例#1: 1 说明 20%数据 ...

  5. Excuse me?这个前端面试在搞事!

    金三银四搞事季,前端这个近年的热门领域,搞事气氛特别强烈,我朋友小伟最近就在疯狂面试,遇到了许多有趣的面试官,有趣的面试题,我来帮这个搞事 boy 转述一下. 以下是我一个朋友的故事,真的不是我. f ...

  6. oid和节点名称

    由于单篇文档最大字限制是40000个字符,不能将OID附上,因此写出我是如何得到这些OID的. 1.安装NET-SNMP yum install net-snmp yum install net-sn ...

  7. PL/SQL学习笔记(三)

    -----创建一个序列,再创建一个表(主键是数字),通过序列生成该表的主键值. create table mytb1( m_id number primary key, m_name ) not nu ...

  8. ASP.NET Core 企业级开发架构简介及框架汇总 (转载)

    ASP.NET Core 企业开发架构概述 企业开发框架包括垂直方向架构和水平方向架构.垂直方向架构是指一个应用程序的由下到上叠加多层的架构,同时这样的程序又叫整体式程序.水平方向架构是指将大应用分成 ...

  9. react基础语法(三)组件的创建和复合组件

    <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title> ...

  10. ubuntu 安装 pcap

    最近在做负载均衡配置,希望将多个dhcp服务配置成一个虚拟dhcp地址,实现dhcp服务高可用.然而配置完成后却发现一个问题,该如何测试呢. 因此就要用上python了,然后ubuntu下面用pip ...