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 ...
随机推荐
- 原生 js 时钟实现
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- NGUI实现简单的倒计时组件
using System; using UnityEngine; public enum ETimerType { CommonFormat, // 78 77 76 75 ... TimeForma ...
- aria2c --enable-rpc --rpc-listen-all -D
在后台启动的方法,如题, 用来配合 web-aria2
- FMUtils.KeyboardHook 轻量级键盘监听器
Nuget添加引用 Install-Package FMUtils.KeyboardHook 调用示例: var KeyboardHook = new Hook("Global Action ...
- 输入每个值连续出现几次的问题(其中包括while括号中出现任意输入问题)
#include<iostream> int main() { //统计输入的每个值,连续出现了多少次 std::cout<<" please enter the n ...
- Leetcode 105
/** * Definition for a binary tree node. * struct TreeNode { * int val; * TreeNode *left; * TreeNode ...
- Ajax中Delete请求参数 后台无法获取的解决方法(Restful风格)
方法一: 在ajax中写入data来传参时,直接把参数拼接到url后面 例如: $.ajax({ url: '/cyberspace/vrv/event/delete/1002?startTime=& ...
- sql 判断字符串中是否含有数字和字母
判断是否含有字母 select PATINDEX('%[A-Za-z]%', ‘ads23432’)=0 (如果存在字母,结果<>1) 判断是否含有数字 PATINDEX('%[0-9]% ...
- Python Django 之 Template 模板语言简介
一.什么事模板语言 html+逻辑控制语句 二.模板语言的作用 帮助前端处理后端发来的数据,方便前端展示(杂糅渲染) 三.模板语言语法 1.{{变量}} 变量使用双大括号{{}} 2.万能的句点号. ...
- 《Python》 基础数据类型和for循环
一.基础数据类型 总览 int:用于计算,计数,运算等.1.2.3.100... str:‘这些内容’,用于少量数据的存储,便于操作. bool:True,False,两种状态,机器反馈给用户的对,错 ...