Codeforces 651 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副画作的美丽值,现在要将他们排成一行。求出游客能获得的最大幸福值。
我想的就是找出美丽值最多的那个数,把剩下的所有的值都和这个最多的数值比较,反正要么比这个数大,要么比这个数小,都可以的。
不会什么优先队列之类的,药丸。。。只会怎么想的就怎么写,也不知道自己写的啥。。。
代码:
#include<bits/stdc++.h>
using namespace std;
bool cmp(int x,int y){
return x>y;
}
int main(){
int n,ans,a[1050],b[1050];
while(~scanf("%d",&n)){
ans=0;
memset(b,0,sizeof(b));
for(int i=0;i<n;i++){
scanf("%d",&a[i]);
b[a[i]]++;
}
sort(b,b+1050,cmp); //这里就是排序把最多的那个数的次数放在最前面,把剩下的加起来就可以了。
for(int i=1;i<1050;i++)
ans+=b[i];
printf("%d\n",ans);
}
return 0;
}
Codeforces 651 B. Beautiful Paintings的更多相关文章
- codeforces 651B B. Beautiful Paintings
B. Beautiful Paintings time limit per test 1 second memory limit per test 256 megabytes input standa ...
- 【CodeForces 651B】Beautiful Paintings 排序+贪心
题目大意: 给定集合,对于任意一个的排列,记,求. 很明显每次搞出一个长度为的最长上升序列,然后把元素给删掉,答案增加. 直接暴力需要. 但是可以进行优化. 设有个,将个数从小到大排序,记为长度为的数 ...
- Codeforces Round #345 (Div. 2) B. Beautiful Paintings 暴力
B. Beautiful Paintings 题目连接: http://www.codeforces.com/contest/651/problem/B Description There are n ...
- 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 time limit per test 1 second memory limit per test 256 megabytes input standa ...
- [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-所有数字出现次数最大值.
- Codeforces 651B Beautiful Paintings【贪心】
题意: 给定序列,重新排序,使严格上升的子序列最多.求这些子序列总长度. 分析: 贪心,统计每个元素出现次数,每次从剩余的小的开始抽到大的,直到不再剩余元素. 代码: #include<iost ...
随机推荐
- 颜色采集器colpick Color Picker
简单 RGB.HSB.十六进制颜色选取器 jQuery 插件. 非常直观类似 Photoshop 的界面. 光明和黑暗很容易自定义 CSS3 外观. 28 KB 总由浏览器加载看起来不错甚至在 IE7 ...
- [CQOI2012]局部极小值
题目链接 注意到\(4\times 7\)的矩阵的局部极小值最多只有8个,可以状压. 设\(f[i][sta]\)表示从小到大填数,当前填到\(i\),极小值的填充状态为\(sta\)的方案数. 考虑 ...
- [Leetcode] Same tree判断是否为相同树
Given two binary trees, write a function to check if they are equal or not. Two binary trees are con ...
- Vim使用小记(一)常用操作
By francis_hao Sep 22,2016 vim的功能自然不止如此,这里只是把日常使用频率较高的记录下来,若想了解vim的全部功能可查阅其帮助手册:help,或者查询指定命令的用法: ...
- 原生toolbar基本使用教程
1.先写布局文件 <android.support.v7.widget.Toolbar android:id="@+id/toolbar" app:title=" ...
- JavaScript 页面间传值
转自:http://blog.csdn.net/qq380107165/article/details/7330612 一:JavaScript静态页面值传递之URL篇 能过URL进行传值,把要传递的 ...
- Linux echo命令打印带有颜色的字
一.命令格式如下: echo -e "\033[字背景颜色;文字颜色m字符串\033[0m" 例如: echo -e ...
- LABVIEW伺服电机测试平台
遇见的关键问题总结: 怎么发脉冲:(1)保持电平一段时间进行翻转(2)仿真脉冲 怎样测试脉冲数:通过检测当前时刻和前一时刻的电平是否相同(通过反馈或者移位寄存器实现)来检测脉冲跳变 通过编码器测量速度 ...
- bzoj 1083 最小生成树
裸的最小生成树. /************************************************************** Problem: User: BLADEVIL Lan ...
- Python学习笔记 - day3 - 数据类型及运算符
Python的数据类型 计算机顾名思义就是可以做数学计算的机器,因此,计算机程序理所当然地可以处理各种数值.但是,计算机能处理的远不止数值,还可以处理文本.图形.音频.视频.网页等各种各样的数据,不同 ...