codeforces 651B 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.
题意:要你把这些数能排成多少个上升序列,最后用数的个数减去序列的个数就是结果,所以序列尽量少;
AC代码:
#include <bits/stdc++.h>
using namespace std;
const int N=1005;
int a[N],flag[N];
int main()
{
int n;
scanf("%d",&n);
memset(flag,0,sizeof(flag));
for(int i=0;i<n;i++)
{
scanf("%d",&a[i]);
}
sort(a,a+n);
for(int i=0;i<n;i++)
{
flag[a[i]]++;
}
int ans=0;
while(n)
{
int num=0;
for(int i=1;i<=1000;i++)
{
if(flag[i]>0)
{
flag[i]--;
num++;
n--;
}
}
ans+=num-1;
}
printf("%d\n",ans); return 0;
}
codeforces 651B B. Beautiful Paintings的更多相关文章
- 【CodeForces 651B】Beautiful Paintings 排序+贪心
		
题目大意: 给定集合,对于任意一个的排列,记,求. 很明显每次搞出一个长度为的最长上升序列,然后把元素给删掉,答案增加. 直接暴力需要. 但是可以进行优化. 设有个,将个数从小到大排序,记为长度为的数 ...
 - Codeforces 651 B. Beautiful Paintings
		
B. Beautiful Paintings time limit per test 1 second memory limit per test 256 megabytes input stan ...
 - 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 Round #345 (Div. 2)——B. Beautiful Paintings(贪心求上升序列个数)
		
B. Beautiful Paintings time limit per test 1 second memory limit per test 256 megabytes input standa ...
 - [刷题codeforces]651B/651A
		
651B Beautiful Paintings 651A Joysticks 点击可查看原题 651B是一个排序题,只不过多了一步去重然后记录个数.每次筛一层,直到全为0.从这个题里学到一个正确姿势 ...
 - [codeforces 55]D. Beautiful numbers
		
[codeforces 55]D. Beautiful numbers 试题描述 Volodya is an odd boy and his taste is strange as well. It ...
 - CodeForces 651B Beautiful Paintings 贪心
		
A. Joysticks time limit per test 1 second memory limit per test 256 megabytes input standard input o ...
 - Beautiful Paintings CodeForces - 651B (贪心)
		
大意: 给定序列$a$, 可以任意排序, 求最大下标i的个数, 满足$a_i<a_{i+1}$. 这个贪心挺好的, 答案就为n-所有数字出现次数最大值.
 
随机推荐
- MS SQL 分类汇总参数 grouping(**)=1 rollup cubt
			
转:http://www.111cn.net/database/mssqlserver/43368.htm 本文章介绍了关于sql多级分类汇总实现方法及数据结构,有碰到问题的同学可参考一下. 据库结构 ...
 - NYOJ-欧几里得
			
欧几里得 时间限制:1000 ms | 内存限制:65535 KB 难度:0 描写叙述 已知gcd(a,b)表示a,b的最大公约数. 如今给你一个整数n,你的任务是在区间[1,n)里面找到一个最大 ...
 - Hadoop 101: Programming MapReduce with Native Libraries, Hive, Pig, and Cascading
			
和Hadoop交互的四种方法: 1. Native Libraries 2. Hive 3. Pig 4. Cascading At a high level, people use the nati ...
 - Linux进程间通信(二) - 消息队列
			
消息队列 消息队列是Linux IPC中很常用的一种通信方式,它通常用来在不同进程间发送特定格式的消息数据. 消息队列和之前讨论过的管道和FIFO有很大的区别,主要有以下两点(管道请查阅我的另一篇文章 ...
 - Linux中的关机
			
我是用普通用户登录,在终端下输入shutdown命令,结果显示 command not found.这就奇怪了,难道我的linux不支持这个命令?man了一下shutdown,大篇幅的说明告诉我,我的 ...
 - 【BZOJ1345】[Baltic2007]序列问题Sequence 贪心+单调栈
			
[BZOJ1345][Baltic2007]序列问题Sequence Description 对于一个给定的序列a1, …, an,我们对它进行一个操作reduce(i),该操作将数列中的元素ai和a ...
 - 【BZOJ2322】[BeiJing2011]梦想封印 高斯消元求线性基+DFS+set
			
[BZOJ2322][BeiJing2011]梦想封印 Description 渐渐地,Magic Land上的人们对那座岛屿上的各种现象有了深入的了解. 为了分析一种奇特的称为梦想封印(Fantas ...
 - SpringMVC结合REST
			
一.什么是REST REST即 Representational State Transfer,也就是(资源)表现层状态转化.资源是指网络上的一个实体或者说是网络上的一个具体信息. 每种资源对应一个特 ...
 - spider_action
			
spider from mobile to mobile to mobile from selenium import webdriver from selenium.webdriver.chrome ...
 - thymeleaf基本应用
			
Thymeleaf是个XML/XHTML/HTML5模板引擎,可以用于Web与非Web应用. Thymeleaf的主要目标在于提供一种可被浏览器正确显示的.格式良好的模板创建方式,因此也可以用作静态建 ...