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.

题意:求最多的上升序列的个数,用map比数组快多,做法:切蛋糕一样每次切一层

代码:

#include<iostream>
#include<algorithm>
#include<vector>
#include<sstream>
#include<map>
using namespace std;
int main(void)
{
int t,n,i,j,be,sum,ans;
while (cin>>n)
{
map<int,int>list;
for (i=0; i<n; i++)
{
cin>>be;
list[be]++;
}
ans=0;
while (n)//每次
{
int num=0;
for (map<int,int>::iterator it=list.begin(); it!=list.end(); it++)
{
if(it->second>0)
{
(it->second)--;
n--;
num++;
}
}
ans=ans+num-1;//两个以上才算一个上升序列
}
cout<<ans<<endl;
}
return 0;
}

Codeforces Round #345 (Div. 2)——B. Beautiful Paintings(贪心求上升序列个数)的更多相关文章

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

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

  2. cf之路,1,Codeforces Round #345 (Div. 2)

     cf之路,1,Codeforces Round #345 (Div. 2) ps:昨天第一次参加cf比赛,比赛之前为了熟悉下cf比赛题目的难度.所以做了round#345连试试水的深浅.....   ...

  3. Codeforces Round #345 (Div. 2)【A.模拟,B,暴力,C,STL,容斥原理】

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

  4. Codeforces Round #345 (Div. 2)

    DFS A - Joysticks 嫌麻烦直接DFS暴搜吧,有坑点是当前电量<=1就不能再掉电,直接结束. #include <bits/stdc++.h> typedef long ...

  5. Codeforces Round #345 (Div. 2) B

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

  6. codeforces水题100道 第十三题 Codeforces Round #166 (Div. 2) A. Beautiful Year (brute force)

    题目链接:http://www.codeforces.com/problemset/problem/271/A题意:给你一个四位数,求比这个数大的最小的满足四个位的数字不同的四位数.C++代码: #i ...

  7. Codeforces Round #277 (Div. 2)C.Palindrome Transformation 贪心

    C. Palindrome Transformation     Nam is playing with a string on his computer. The string consists o ...

  8. Codeforces Round #181 (Div. 2) C. Beautiful Numbers 排列组合 暴力

    C. Beautiful Numbers 题目连接: http://www.codeforces.com/contest/300/problem/C Description Vitaly is a v ...

  9. Codeforces Round #566 (Div. 2) C. Beautiful Lyrics

    链接: https://codeforces.com/contest/1182/problem/C 题意: You are given n words, each of which consists ...

随机推荐

  1. UVA 12898 - And Or 与和或 (思路题)

    思路就是有零一变化的位Or以后一定是1,And以后一定是0:那么如果b的二进制更长那么就把包含a的部分全部置为1或0,如果一样长那么就把不同的部分置为1或0. 今天被这题坑的地方:1默认是int,如果 ...

  2. cv2.getPerspectiveTransform 透视变换

    简介 透视变换(Perspective Transformation)是将成像投影到一个新的视平面(Viewing Plane),也称作投影映射(Projective Mapping).如图1,通过透 ...

  3. linux命令行调试邮件服务器

    linux命令行调试邮件服务器 1. Linux客户端调试邮件过程 [root@mxtest ~]# telnet mail.xx.com 25 Trying 172.16.236.103... Co ...

  4. Mac下快捷键的符号所对应的按键

  5. 【转】matlab练习程序(奇异值分解压缩图像)

    介绍一下奇异值分解来压缩图像.今年的上半年中的一篇博客贴了一篇用奇异值分解处理pca问题的程序,当时用的是图像序列,是把图像序列中的不同部分分离开来.这里是用的不是图像序列了,只是单单的一幅图像,所以 ...

  6. Android读书笔记二

    本章讲到需要Android应用程序以及Android NDK程序来测试Linux驱动,所以所需要的工具都必须配备好.而且对工具的版本也是有一些要求,JDK,Eclipse,ADT,CDT,Androi ...

  7. wdcp 使用说明总结(持续更新中。。。)

    wdcp 使用说明总结(持续更新中...) 1.移动文件时,如果是上一层,直接填写../即可

  8. 在ArchLinux、manjaro中安装MySql(mariaDB)

    安装MySql数据库.但是在MySql被Oracle收购之后,很多开源支持者就转而使用MariaDb了.不过MariaDb也和MySql兼容的,所以基本不用有什么担心.由于ArchLinux只带了Ma ...

  9. apply 与 lambda

    Python中的lambda和apply用法  https://blog.csdn.net/anshuai_aw1/article/details/82347016

  10. Python头脑风暴4

    IT是全国平均薪资最高的行业,2017年全国最高,人均13点4万每年. 但技术固然好,创业拼的还是世界观下的创意. 蘑菇街,并夕夕,TikTok,头条,哪个不是创意用IT技术的现实化?? 未来,大平台 ...