题目链接:https://vjudge.net/contest/237394#problem/B

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.

Examples

Input
520 30 10 50 40

Output
4

Input
4200 100 100 200

Output
2

Note

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,有n个数,你可以任意排序,要求a[i+1]>a[i]的数对最多

个人思路:额。。。这题wa了三次,一直在想思路哪里有问题,其实是有问题的,后来改了思路,正确的思路是:

先把数从小到大排序,找出按完全递增顺序排列的一组数,然后排除这些数,剩余的数又按完全递增的顺序排列····,一直循环此过程,直到结束

看代码

#include<iostream>
#include<cstdio>
#include<cstring>
#include<stdio.h>
#include<string.h>
#include<cmath>
#include<math.h>
#include<algorithm>
#include<set>
#include<queue>
typedef long long ll;
using namespace std;
const ll mod=1e9+7;
const int maxn=1e5+10;
const ll maxa=32050;
const double x=(1.0+sqrt(5.0))/2;
#define INF 0x3f3f3f3f3f3f
int main()
{int n,ans=0,sum=0;int a[1100];cin>>n;for(int i=0;i<n;i++)cin>>a[i];sort(a,a+n);for(int i=1;i<n;i++){if(a[i]>a[i-1]){sum++;}else{int t=upper_bound(a+i,a+n,a[i-1])-a;// cout<<t<[[<' ';if(t!=n){swap(a[i],a[t]);sum++;}else{ans+=sum;sum=0;sort(a+i,a+n);//  for(int j=i;j<n;j++)//    cout<<a[j]<<' ';//cout<<ans<<endl;
            }}}ans+=sum;cout<<ans<<endl;return 0;
}

上面是本人ac的代码,然后刚刚看了一下别人的博客,发现总是会有大神有更快的算法

每次的答案就是:总个数-出现次数最多的数的个数

那么,为什么是这样呢?  本人比较菜,想了许久,看了别人的博客说法,看不懂,然后自己按着公式来推,发现是可以推出来的

比如样例是1 1 1  2 2 3 3 3 3 ,那么出现次数最多的就四次,也就是4个三,第二多的是三次,三个2,最少的四两次,两个2,排法如下:

最多的是3 3 3 3,插入第二多的就变成了1 3 1 3 1 3 3,然后最少的2,不管2是大于还是小于都可以插进去,只是插前面或者后面的区别罢了,这里是插在1的

后面变为1 2 3 1 2 3 1 3 3,这就是答案了。

看代码

#include<iostream>
#include<cstdio>
#include<cstring>
#include<stdio.h>
#include<string.h>
#include<cmath>
#include<math.h>
#include<algorithm>
#include<set>
#include<queue>
typedef long long ll;
using namespace std;
const ll mod=1e9+7;
const int maxn=1e5+10;
const ll maxa=32050;
const double x=(1.0+sqrt(5.0))/2;
#define INF 0x3f3f3f3f3f3f
int main()
{int n,maxx=0,t;int a[1100];memset(a,0,sizeof(a));cin>>n;for(int i=0;i<n;i++){cin>>t;a[t]++;maxx=max(maxx,a[t]);}cout<<n-maxx<<endl;return 0;
}

转载于:https://www.cnblogs.com/caijiaming/p/9340308.html

B - Beautiful Paintings相关推荐

  1. codeforces 651B B. Beautiful Paintings(贪心JAVA代码)

    题目链接: codeforces 651B 题目描述: 给出一组数,重新排列这组数,得到 ai<ai+1 a_i的最多次数,求取这个最多的次数的值. 题目分析: 最优解的情况一定我们找到最小的数 ...

  2. Codeforces Round #345 (Div. 2)

    DFS A - Joysticks 嫌麻烦直接DFS暴搜吧,有坑点是当前电量<=1就不能再掉电,直接结束. #include <bits/stdc++.h>typedef long ...

  3. 风景类Midjouney prompt提示词

    稳定输出优美风景壁纸的Midjouney prompt提示词. 1\在夏夜,有淡蓝色的星空,海边,流星,烟花,海滩上全是蓝色的玫瑰和绿色的植物,由Ivan Aivazovsky和Dan Mumford ...

  4. cartoon drawing_卡通绘画(Cartoon drawing)

    卡通绘画(Cartoon drawing)详情 给你一点时间,这个画板可以帮你完成漂亮画作,你可以和你的孩子一起完成,你的家人,你的朋友一起完成它,不需要过多的处理,只需要选择适当的颜色,使画面更漂亮 ...

  5. knockout+html绑定,Knockout.Js官网学习(style绑定、attr绑定)

    Style绑定 style绑定是添加或删除一个或多个DOM元素上的style值.比如当数字变成负数时高亮显示,或者根据数字显示对应宽度的Bar.(注:如果你不是应用style值而是应用CSS clas ...

  6. 1-笑话幽默-英语文章阅读

    Two brothers were looking at some beautiful paintings. (兄弟俩在看一些漂亮的油画.) "Look,"said the eld ...

  7. cartoon drawing_‎App Store 上的“卡通绘画(Cartoon drawing)”

    给你一点时间,这个画板可以帮你完成漂亮画作,你可以和你的孩子一起完成,你的家人,你的朋友一起完成它,不需要过多的处理,只需要选择适当的颜色,使画面更漂亮.这非常简单不是吗?你需要对不同颜色进行认识,并 ...

  8. Python Beautiful Soup类的基本元素

    Beautiful Soup库是解析,遍历,维护"标签树"的功能库. 条件: pip install lxml pip install html5lib 以下5种基本元素是使用方法 ...

  9. Python爬虫利器之Beautiful Soup的全世界最强用法 五百行文章!

    0. 前言 爬虫是一个非常有意思的东西,比如自己做的一个网页上面什么数据都没有就可以爬虫别人的 然后进行去重 数据分析等等 在这里因为爬虫涉及到的方面非常多 1. Beautiful Soup的简介 ...

最新文章

  1. 云上的可观察性数据中台,如何构建?
  2. Visual Studio 2017 的重大功能回顾和针对 .NET 开发者的更新
  3. Linux 系统应用编程——网络编程(利用TCP/IP 模型分析数据传输过程)
  4. 【转载保存】java操作HDFS
  5. 10-10-020-简介-kafka的ZK上面的存储
  6. 系统上云服务器地址,可以自己安装系统的云服务器地址
  7. 6 年成为 AIoT 独角兽,这位 17 年连续创业者是如何做到的?
  8. 计算机组装的虚拟仿真实验报告,组装计算机的虚拟实验室
  9. 电镜的成像原理-冷冻电镜成像技术1
  10. 存用部首查字典如何查_SCI文献阅读技巧:3位博士总结如何看文献,干货满满!...
  11. 实验板FPGA型号在哪里看_【VE】一文看懂乙烯基树脂发展史!
  12. 腾讯专访 | 子芽:代码疫苗技术,赋能数字化应用内生安全自免疫
  13. MENTOR 安装过程
  14. 视频联网云平台EasyCVR集成海康EHome协议系列——Ehome协议调用流程介绍
  15. 设备一路485如何供两台电脑使用_干货!消防设备供电系统有哪些部分构成,用电负荷等级如何划分?...
  16. 【步兵 cocos2dx】热更新(下)
  17. emuelec 镜像太大无法写入U盘解决方法
  18. 弹幕网站开发(只有前端)
  19. ilm 和dlm差异_差异表达基因的几种筛选方法.pdf
  20. Unity Shader - PBR 渲染 SP 导出的素材

热门文章

  1. MySQL Root密码丢失解决方法总结
  2. Electron 打包Mac安装包代码签名问题解决方案Could not get code signature for running application
  3. 【报告分享】2021-2022年中国人工智能创投数据报告.pdf(附下载链接)
  4. 【报告分享】阿里巴巴全生态就业体系与就业质量研究报告.pdf(附下载链接)...
  5. 【报告分享】智能时代的商业地产数字变革与发展报告.pdf(附下载链接)
  6. Graph Embedding及其在知乎的实践(附pdf下载链接)
  7. anaconda显示ImportError: cannot import name ‘secure_write‘
  8. 腾讯广告算法大赛高分秘籍来袭!大咖直播详解TI-ONE与Angel框架
  9. jdbc数据库配置mysql数据库_JDBC连接MySQL数据库(一)——数据库的基本连接
  10. linux查看文件元数据,Linux切换目录、查看目录下的文件、文件类型介绍和查看文件的元数据信息...