Beautiful Paintings
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.
Input
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.
Output
Print one integer — the maximum possible number of neighbouring pairs, such that ai + 1 > ai, after the optimal rearrangement.
Example
Input Output Input Output
Note
In the first sample, the optimal order , , , , . In the second sample, the optimal order , , , .
below is my code
#include <iostream>
using namespace std;
int main( )
{
int num;
int arr[1001];
while(cin>>num)
{
int i,temp,counter=0;
for(i=0;i<1001;i++)
arr[i]=0;
for(i=0;i<num;i++)
{
cin>>temp;
arr[temp]++;
}
for(i=1;i<=1000;i++)
{
for(temp=1;temp<=1000;temp++)
{
if(arr[temp]!=0)
{
arr[temp]--;
break;
}
}
for(temp++;temp<=1000;temp++)
{
if(arr[temp]!=0)
{
arr[temp]--;
counter++;
}
}
}
cout<<counter<<endl;
}
return 0;
}
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 ...
- B. Beautiful Paintings
time limit per test 1 second memory limit per test 256 megabytes input standard input output standar ...
- 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 ...
随机推荐
- 读Kafka Consumer源码
最近一直在关注阿里的一个开源项目:OpenMessaging OpenMessaging, which includes the establishment of industry guideline ...
- NSUserDefault
NSUserDefault是Cocoa提供的默认应用程序状态保持接口.它提供了简化的plist文件持久化方法.通过NSUserDefault类,你可以把用户首选项保存到plist文件中.到应用程序结束 ...
- codeforces 897B Chtholly's request 偶数长度回文数
codeforces 897B Chtholly's request 题目链接: http://codeforces.com/problemset/problem/897/B 思路: 暴力求出这100 ...
- 获取或设置当前窗口contextmenu事件的事件处理函数
在浏览器中 鼠标右键点击会显示默认的 自带的菜单,那么如何禁止 和更改呢? 1) 禁止右键 window.oncontextmenu = funcRef; //funcRef是个函数引用 列子: w ...
- 实战-Mysql5.6.36脚本编译安装及初始化
概述 本文为centos7.3自动化编译安装mysql5.3.6的脚本及后续初始化操作,话不多少,直接上脚本. 安装脚本install.py如下: #coding=utf-8 #!/usr/bin/p ...
- Chrome浏览器读写系统剪切板
IE浏览器支持直接读写剪切板内容: window.clipboardData.clearData(); window.clipboardData.setData('Text', 'abcd'); 但是 ...
- 关于使用scrapy框架编写爬虫以及Ajax动态加载问题、反爬问题解决方案
Python爬虫总结 总的来说,Python爬虫所做的事情分为两个部分,1:将网页的内容全部抓取下来,2:对抓取到的内容和进行解析,得到我们需要的信息. 目前公认比较好用的爬虫框架为Scrapy,而且 ...
- UWP 调用outlook邮箱反馈
public static async Task FeedbackAsync(string address, string subject, string body) { if (address == ...
- python的简介及入门
前言 为何使用Python Python 是一种效率极高的语言.与其他众多的语言相比,实现相同功能,使用Python编写的程序包含的代码更少.Python的语法简单,易上手,使用Python编写的代码 ...
- 【Java入门提高篇】Day8 Java内部类——匿名内部类
今天来看看另一个更加神奇的类--匿名内部类. 就像它的名字表示的那样,这个类是匿名的,用完之后,深藏功与名,就像扫地僧那样默默潜藏于深山之中.匿名内部类不仅没有名字,连class关键字都省掉了,而且匿 ...