B. Beautiful Paintings
1 second
256 megabytes
standard input
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.
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.
Print one integer — the maximum possible number of neighbouring pairs, such that ai + 1 > ai, after the optimal rearrangement.
5
20 30 10 50 40
4
4
200 100 100 200
2
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.
思维,考虑一个没有重复的几个数,结果是n-1,那么如果有重复的数,就先不管重复的数各取一个组成一个序列,再把剩下的各取一个组成一个序列,能够组成m个序列,m是重复数字最多的个数,结果就是n-m.
#include <iostream>
#include <algorithm>
#include <map>
using namespace std; int main()
{
int n,m=,d;
map<int,int>p;
cin>>n;
for(int i=;i<n;i++)
{
cin>>d;
p[d]++;
if(p[d]>m)m=p[d];
}
cout<<n-m;
}
B. Beautiful Paintings的更多相关文章
- codeforces 651B Beautiful Paintings
B. Beautiful Paintings time limit per test 1 second memory limit per test 256 megabytes input standa ...
- Codeforces Round #345 (Div. 2) B. Beautiful Paintings 暴力
B. Beautiful Paintings 题目连接: http://www.codeforces.com/contest/651/problem/B Description There are n ...
- Codeforces 651 B. Beautiful Paintings
B. Beautiful Paintings time limit per test 1 second memory limit per test 256 megabytes input stan ...
- codeforces 651B B. Beautiful Paintings
B. Beautiful Paintings time limit per test 1 second memory limit per test 256 megabytes input standa ...
- 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 ...
- Beautiful Paintings
There are n pictures delivered for the new exhibition. The i-th painting has beauty ai. We know that ...
- CodeForces 651B Beautiful Paintings 贪心
A. Joysticks time limit per test 1 second memory limit per test 256 megabytes input standard input o ...
- 【CodeForces 651B】Beautiful Paintings 排序+贪心
题目大意: 给定集合,对于任意一个的排列,记,求. 很明显每次搞出一个长度为的最长上升序列,然后把元素给删掉,答案增加. 直接暴力需要. 但是可以进行优化. 设有个,将个数从小到大排序,记为长度为的数 ...
- codeforce 651B Beautiful Paintings
题意:后一个比前一个大就加一,问最大次数. #include<cstdio> #include<cstring> #include<algorithm> #incl ...
随机推荐
- 多年未写过java了
java面试必须了解和记忆的知识点(linux,nginx,数据库之类的暂时不考虑了) java面试的115常见问题,这个博客还是不过的推荐一下吧 http://www.importnew.com/1 ...
- php7-soap调用wsdl接口报错:Could not connect to host
由php5.6升级到php7.1以上版本,在用soap调用wsdl接口是报错:Could not connect to host 后来经过排查是centos服务器上装有2个版本的openssl造成的. ...
- Yii中的CComponent应用实例
首先我们先了解一下如何创建一个CComponent,手册讲述如下: CComponent 是所有组件类的基类. CComponent 实现了定义.使用属性和事件的协议. 属性是通过getter方法或/ ...
- android--------WebView实现 Html5 视频标签加载
自Android 4.4起,Android中的WebView开始基于Chromium(谷歌浏览器)支持浏览器的一系列功能,webkit解析网页各个节点,这个改变,使得WebView的性能大幅度提升,并 ...
- 诡异的小bug 自动生成font标签包裹span标签中的文字
某天测试自己写的网站的时候突然发现页面上一些文字排版出现了一些奇怪的错乱,在控制台发现错乱的文字被font标签包裹着 ,但是代码中根本没用用到font标签 后来发现是因为自己不小心点了谷歌浏览器地址栏 ...
- 获取Oracle数据库awr报告方法
--登录数据库 sqlplus username/passwd; --运行生成AWR报告脚本 SQL> @?/rdbms/admin/awrrpt.sql; --输入要生成报告的格式:htm ...
- 循环大法——一次性理清forEach/for-in/for/$each
国寿的这个项目写得我基础都忘完了 近期会把vue和基础都并行复习.学习 forEach 适用于调用数组的每个元素,并将元素传递给回调函数,但是空数组是不会执行回调函数的.forEach适用于集合中的对 ...
- httpclient http状态管理
HTTP状态管理 最初,Htt被设计成一个无状态的面向请求响应的协议,所以它不能再逻辑相关的http请求/响应中保持状态会话. 由于越来越多的系统使用http协议,其中包括http从来没有想支持的系统 ...
- L1-004 计算摄氏温度
给定一个华氏温度F,本题要求编写程序,计算对应的摄氏温度C.计算公式:C=5×(F−32)/9.题目保证输入与输出均在整型范围内. 输入格式: 输入在一行中给出一个华氏温度. 输出格式: 在一行中按照 ...
- Swift网络封装库Moya中文手册之Plugins
Plugins Moya plugins用于反映请求的发起或接收.Plugins定义为 PluginType 属性,可以在请求准备发起和接收到返回数据时回调. Built in plugins Moy ...