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 ...
随机推荐
- Android 修改系统默认density
如你所知在Anroid N 中,系统添加了多个级别的密度值供用户选择. 系统的默认的值就是 ro.sf.lcd_density 同时其他级别的默认值的大小基础也是以默认值为基础,然后乘以不同的比例得到 ...
- leetcode-电话号码的字母组合
电话号码的字母组合 给定一个仅包含数字 2-9 的字符串,返回所有它能表示的字母组合. 给出数字到字母的映射如下(与电话按键相同).注意 1 不对应任何字母. 示例: 输入:"23" ...
- hdu刷题2
hdu1021 给n,看费波纳列数能否被3整除 算是找规律吧,以后碰到这种题就打打表找找规律吧 #include <stdio.h> int main(void) { int n; whi ...
- 259 [LeetCode] 3Sum Smaller 三数之和较小值
题目: Given an array of n integers nums and a target, find the number of index triplets i, j, k with 0 ...
- 20170413B端业务访问故障排查思路
现象: 1.全国用户电视端页面无法显示,刷不出版面. 2.后端服务无法打开,报错,504,502 显示服务器端业务故障超时. 3.其他业务也出现缓慢情况,并不严重. 排查: 1.系统服务排查,常规 ...
- 如何理解*p++
后置递增运算符的优先级高于解引用运算符! *p++ 等价于 *(p++) 但是,我们*p++的求值结果不可理解为p+1指向的对象的值,而应该是p指向的对象的值. 这是由于后置++的特性引起的. *p+ ...
- Alpha发布-----欢迎来怼团队
欢迎来怼项目小组—Alpha发布展示 一.小组成员 队长:田继平 成员:葛美义,王伟东,姜珊,邵朔,冉华 ,李圆圆 二.文案+美工展示 链接:http://www.cnblogs.com/wwd199 ...
- 基于spec评论“欢迎来怼”团队Alpha版作品
“欢迎来怼”团队的作品是手机版博客园 1.获取此博客园app的方式——二维码 通过扫描二维码的方式下载app,这是当今比较流行的方式,适合广大手机的使用者——青少年的使用习惯. 2.点击图标,进入该a ...
- 20145214 《Java程序设计》第2周学习总结
20145214 <Java程序设计>第2周学习总结 教材学习内容总结 基本类型 整数:可分为short整数.int整数.long整数. 字节:即byte类型,可表示-128~127的整数 ...
- c#笔记整理 关于继承与多态等
[ 塔 · 第 二 条 约 定 ] c#面向对象基础 整理private.protected.public.abstract等的异同 public 公有访问.不受任何限制. private 私有访问. ...