CF651B-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<bits/stdc++.h>
using namespace std;
const int N=1000+10;
int a[N];
int main()
{
int n,i,j,x;
while(~scanf("%d",&n))
{
x=0;
for(i=0;i<n;i++)
scanf("%d",&a[i]);
sort(a,a+n);
int k=1;
for(i=0;i<n-1;i++)
{
for(j=k;j<n;j++)
if(a[j]>a[i])
{
k=j+1;//下次直接从k开始找,避免重复问题;
x++;
break;
}
}
printf("%d\n",x);
}
return 0;
}
CF651B-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 ...
- Beautiful Paintings
There are n pictures delivered for the new exhibition. The i-th painting has beauty ai. We know that ...
- 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 ...
随机推荐
- Hibernate5 与 Spring Boot2 最佳性能实践
参考 Hibernate5 与 Spring Boot2 最佳性能实践(1) Hibernate5 与 Spring Boot2 最佳性能实践(2) Best Performance Practice ...
- 利用贝塞尔曲线绘制(UIBezierPath)自定义iOS动态速度表,可以自定义刻度,刻度值,进度条样式
GitHub的Demo下载地址 使用UIBezierPath画图步骤: 创建一个UIBezierPath对象 调用-moveToPoint:设置初始线段的起点 添加线或者曲线去定义一个或者多个子路径 ...
- [ SNOI 2013 ] Quare
Description 题目链接 求一张无向带权图的边双连通生成子图的最小代价. Solution 核心的思路是,一个点双连通分量肯定是一堆环的并. 考虑增量地构造这个边双连通图,每次把一个环并进去, ...
- JVM内存区域参数配置
转自:https://www.jianshu.com/p/5946c0a414b5 需要提前了解的知识点: JVM内存模型 JVM垃圾回收算法 下图是JVM内存区域划分的逻辑图 JVM内存区域逻辑 ...
- gulp自动化构建工具使用
gulpfile.js: var gulp = require("gulp"); var imagemin = require("gulp-imagemin") ...
- 利用Jenkins打包ISO和QCOW2镜像文件
现在的云虚拟化环境越来越多,经常会碰到需要修改并重新打包新的ISO或QCOW2镜像文件.通过手工的方式会比较麻烦,所以在镜像发布的生产环境中可以利用Jenkins来进行定期打包发布,以下介绍Jenki ...
- docker使用阿里云镜像加速器(属于自己的专属加速器)
https://cr.console.aliyun.com/cn-shanghai/mirrors
- JavaScript轮播图
需求: 鼠标移动到下标页码时,也转换到相对应的图片: 多张图片可以自动轮播: 鼠标移动至图片时,停止自动轮播: 可以手动左右调节: <!DOCTYPE html> <html lan ...
- import downloadjs from 'downloadjs' 如果是自己写的函数 没用默认导出 记得加花括号 例如 import { download } from './data.js'
import downloadjs from 'downloadjs' 如果是自己写的函数 没用默认导出 记得加花括号 例如 import { download } from './data.js'
- jxcel - 好用的Excel与Java对象转换工具
更多精彩博文,欢迎访问我的个人博客 Jxcel简介 Jxcel是一个支持Java对象与Excel(目前仅xlsx.xls)互相转换的工具包. 项目地址:https://github.com/jptan ...