codeforces 651B 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.
题意:在一个序列中,当遇到递增的数时,会觉得开心,现在给一组数,问可以开心几次
分析:求出这个序列中总共有多少个上升的序列,并且没个上升序列中有多少个元素
题解:先将序列从小到大排序,记录所有重复出现的数的次数,去掉出现次数最多的求剩下的数的和即可
#include<stdio.h>
#include<string.h>
#include<string>
#include<math.h>
#include<algorithm>
#define LL long long
#define PI atan(1.0)*4
#define DD double
#define MAX 3000
#define mod 100
#define dian 1.000000011
#define INF 0x3f3f3f
using namespace std;
int s[MAX];
int vis[MAX];
int main()
{
int n,m,j,i,t,k;
while(scanf("%d",&n)!=EOF)
{
for(i=0;i<n;i++)
scanf("%d",&s[i]);
sort(s,s+n);
for(i=0;i<=n;i++)
vis[i]=1;
k=0;
for(i=0;i<n;i++)
{
if(s[i]==s[i+1])
vis[k]++;
else
k++;
}
int sum=0;
sort(vis,vis+k);
for(i=0;i<k-1;i++)
sum+=vis[i];
printf("%d\n",sum);
}
return 0;
}
codeforces 651B Beautiful Paintings的更多相关文章
- 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【贪心】
题意: 给定序列,重新排序,使严格上升的子序列最多.求这些子序列总长度. 分析: 贪心,统计每个元素出现次数,每次从剩余的小的开始抽到大的,直到不再剩余元素. 代码: #include<iost ...
- codeforce 651B Beautiful Paintings
题意:后一个比前一个大就加一,问最大次数. #include<cstdio> #include<cstring> #include<algorithm> #incl ...
- [刷题codeforces]651B/651A
651B Beautiful Paintings 651A Joysticks 点击可查看原题 651B是一个排序题,只不过多了一步去重然后记录个数.每次筛一层,直到全为0.从这个题里学到一个正确姿势 ...
- 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 题目连接: 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 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 55D Beautiful Number
Codeforces 55D Beautiful Number a positive integer number is beautiful if and only if it is divisibl ...
随机推荐
- git push提示或错误
当 git 和 gerrit 一起使用的时候,你创建了一个 tag,现在需要 push 到远程仓库,当你没有权限的时候,会出现如下提示: $ git push origin v20150203 Tot ...
- Spring MVC 的请求参数获取的几种方法
通过@PathVariabl注解获取路径中传递参数 @RequestMapping(value = "/{id}/{str}") public ModelAndView hello ...
- UVa 1648 (推公式) Business Center
题意: 有一种奇怪的电梯,每次只能向上走u个楼层或者向下走d个楼层 现在有m个这种电梯,求恰好n次能够到达的最小楼层数(必须是正数),最开始默认位于第0层. 分析: 假设电梯向上走x次,则向下走n-x ...
- 一个java高级工程师的进阶之路
宏观方面 一. JAVA.要想成为JAVA(高级)工程师肯定要学习JAVA.一般的程序员或许只需知道一些JAVA的语法结构就可以应付了.但要成为JAVA(高级) 工程师,您要对JAVA做比较深入的研究 ...
- datatables使用总结篇
<!doctype html> <html> <head> <meta charset="gbk"/> <meta name= ...
- 【Mac】Mac键盘实现Home, End, Page UP, Page DOWN
* Home键=Fn+左方向 * End键=Fn+右方向 * PageUP=Fn+上方向 * PageDOWN=Fn+下方向 * 向后删除=Fn+delete * Find ...
- 【转】./a.out 2>&1 > outfile
原文网址:http://www.cnblogs.com/zhaoyl/archive/2012/10/22/2733418.html APUE 3.5关于重定向有个容易迷惑人的问题: ./a.out ...
- IE下JS接受ActiveX控件方法
1.常规写法 <SCRIPT type="text/javascript" FOR="activexID" EVENT="onXXXevent( ...
- CodeSmith模板生成
转:http://blog.csdn.net/jason_ldh/article/details/9887073 一. 工具设置 CodeSmith默认是不支持中文的,那么我们必 ...
- android 应用页面与数据申请逻辑剥离;
1.页面与数据申请剥离,数据申请框架可以灵活更换,解耦合: 2.对应页面的数据申请类中,将返回数据解析剥离,灵活更换数据返回及对应解析: 二.模块划分: 1.一些通用的工具类,可以考虑迁移到com.c ...