Codeforces Round #345 (Div. 2) B
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.
题解:在一串序列中 不断的找到单调递增序列 序列中的元素只能用一次
标记处理
#include<bits/stdc++.h>
#include<iostream>
#include<cstdio>
#define ll __int64
using namespace std;
int a[],n,ss[];
int main() {
scanf("%d",&n);
for(int i=;i<=n;i++)
{
scanf("%d",&a[i]);
ss[a[i]]++;
}
int re=;
sort(a+,a+n+);
while()
{
int sm=;
for(int j=;j<=;j++)
{
if(ss[j])
{
sm++;
ss[j]--;
}
}
if(!sm)break;
re+=(sm-);
}
printf("%d\n",re);
return ;
Codeforces Round #345 (Div. 2) B的更多相关文章
- cf之路,1,Codeforces Round #345 (Div. 2)
cf之路,1,Codeforces Round #345 (Div. 2) ps:昨天第一次参加cf比赛,比赛之前为了熟悉下cf比赛题目的难度.所以做了round#345连试试水的深浅..... ...
- 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 ...
- Codeforces Round #345 (Div. 1) C. Table Compression dp+并查集
题目链接: http://codeforces.com/problemset/problem/650/C C. Table Compression time limit per test4 secon ...
- Codeforces Round #345 (Div. 1) E. Clockwork Bomb 并查集
E. Clockwork Bomb 题目连接: http://www.codeforces.com/contest/650/problem/E Description My name is James ...
- Codeforces Round #345 (Div. 1) D. Zip-line 上升子序列 离线 离散化 线段树
D. Zip-line 题目连接: http://www.codeforces.com/contest/650/problem/D Description Vasya has decided to b ...
- Codeforces Round #345 (Div. 2) E. Table Compression 并查集
E. Table Compression 题目连接: http://www.codeforces.com/contest/651/problem/E Description Little Petya ...
- Codeforces Round #345 (Div. 2) D. Image Preview 暴力 二分
D. Image Preview 题目连接: http://www.codeforces.com/contest/651/problem/D Description Vasya's telephone ...
- Codeforces Round #345 (Div. 1) A - Watchmen 容斥
C. Watchmen 题目连接: http://www.codeforces.com/contest/651/problem/C Description Watchmen are in a dang ...
- Codeforces Round #345 (Div. 2) B. Beautiful Paintings 暴力
B. Beautiful Paintings 题目连接: http://www.codeforces.com/contest/651/problem/B Description There are n ...
- Codeforces Round #345 (Div. 2) A. Joysticks dp
A. Joysticks 题目连接: http://www.codeforces.com/contest/651/problem/A Description Friends are going to ...
随机推荐
- Pyhton网络爬虫实例_豆瓣电影排行榜_Xpath方法爬取
-----------------------------------------------------------学无止境------------------------------------- ...
- Django创建App报错
在django下创建APP项目时遇到的坑 python manage.py startapp app01 报错内容如下: 解决:找到报错中的文件夹151行删除items(),)中的逗号即可 在命令行下 ...
- LeetCode 94 ——二叉树的中序遍历
1. 题目 2. 解答 2.1. 递归法 定义一个存放树中数据的向量 data,从根节点开始,如果节点不为空,那么 递归得到其左子树的数据向量 temp,将 temp 合并到 data 中去 将当前节 ...
- solidity 智能合约操作
合约编译 #!/usr/bin/env python # coding: utf8 import json import os # Solc Compiler from functools impor ...
- 官方文档 恢复备份指南三 Recovery Manager Architecture
本节讨论以下问题: About the RMAN Environment 关于RMAN环境 RMAN Command-Line Client ...
- 【转】Charles 从入门到精通
目录与版权 转载请保留顶部的 Charles 中国特惠内容,本文的内容主要包括: Charles 的简介 如何安装 Charles 将 Charles 设置成系统代理 Charles 主界面介绍 过滤 ...
- iscroll手册
概述: 大家在日常工作中最常用的插件是什么,jQurey?Lazyload?但是这些都是在PC端,但是在移动端最常用的插件莫过于iScroll了,iScroll到底是什么东西,应该怎么用?iScrol ...
- iOS- UIButton/UIImageView/UISlider/UISwitch操作
如果看不到图片 可以尝试更换浏览器(推荐Safari ) 一.控件的属性 1.CGRect frame 1> 表示控件的位置和尺寸(以父控件的左上角为坐标原点(0, 0)) 2> 修改这个 ...
- 无法打开mfc120.lib
今天在用VS2013编译OSG的时候报错:无法打开mfc120.lib.仔细查了下资料. 我是这么解决的: 安装Multibyte MFC Library for Visual Studio 2013 ...
- node 第一天
在开发的过程中,几乎不可能一次性就能写出毫无破绽的程序,断点调试代码是一个普遍的需求. 作为前端开发工程师,以往我们开发的JavaScript程序都运行在浏览器端,利用Chrome提供的开发者工具就可 ...