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 ...
随机推荐
- Python -- xlrd,xlwt,xlutils 读写同一个Excel
最近开始学习python,想做做简单的自动化测试,需要读写excel,然后就找到了xlrd来读取Excel文件,使用xlwt来生成Excel文件(可以控制Excel中单元格的格式),需要注意的是,用x ...
- C#读写记事本(txt)文件
C#写入记事本(txt)文件方法一: FileStream stream = new FileStream(@"d:\aa.txt",FileMode.Create);//file ...
- JSP生成验证码
<%@ page language="java" import="java.util.*" pageEncoding="gbk"%&g ...
- windows 网络共享传送文件超慢
这可是无线局域网,竟然只有 200K/s. 调查经过: 1) 问题是单向的, B->A 没有问题, A->B就出事 2) 只发生在 Windows网络共享, A上装了apache测试, A ...
- centos系统lvm的安装
今天安装redhat6.1在分区时提示”可引导分区不能位于逻辑卷上“,原来linux的引导区不能放在逻辑卷上. 解决方法: 1.先建立一个物理分区划给/boot分区 2.剩下的空间划给lvm. 然后开 ...
- 20170528xlVBA凑数一例
Public Sub MakeUp() Dim Sht As Worksheet Set Sht = ThisWorkbook.Worksheets("设置") Dim Total ...
- 4-2 Ajax练习题,12结算!Check Out。
练习题:在购物车的每个商品旁添加按钮,按一下减一个,数量为0删除该商品.先用普通方法再用Ajax支持. 1.自定义方法decrease, 为其设定路径routes.rb. 在resouurces :l ...
- sql 数据库显示 正在恢复
问题原因:Sql Server 一直显示正在恢复.有事务未恢复或者还原数据库造成 处理办法: 步骤一:数据库上右键->任务->分离 步骤二:数据库上右键->任务->脱机 数据库 ...
- Python的数据类型3元组,集合和字典
首先要讲到的就是元组 元组其实拥有列表的一些特性,可以存储不同类型的值,但在某些方面元组又比不上列表 定义一个元组,你可以不用加‘ [ ] ’,你只需用逗号隔开即可 例如 1 2 3 4 5 6 7 ...
- NodeJS之express的路由浅析
路由路径和请求方法一起定义了请求的端点,它可以是字符串.字符串模式或者正则表达式.后端在获取路由后,可通过一系列类似中间件的函数去执行事务. 可使用字符串的路由路径: // 匹配根路径的请求 app. ...