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 ...
随机推荐
- Invitation Cards POJ 1511 SPFA || dij + heap
http://poj.org/problem?id=1511 求解从1去其他顶点的最短距离之和. 加上其他顶点到1的最短距离之和. 边是单向的. 第一种很容易,直接一个最短路, 然后第二个,需要把边反 ...
- JAVA字符串转日期或日期转字符串【转】
JAVA字符串转日期或日期转字符串[转] 文章中,用的API是SimpleDateFormat,它是属于java.text.SimpleDateFormat,所以请记得import进 来! 用法: S ...
- 如何从GAC中拷贝文件出来 C:\Windows\assembly
方法一:命令行拷贝. 开始--运行--cmd--"cd C:\WINDOWS\assembly".一般自己开发的dll都在GAC_MSIL这个文件夹下面,按照我如下的截图就可以拷贝 ...
- Android如何用阿里云的API进行身份证识别
准备工作:在libs下添加 alicloud-Android-apigateway-sdk-1.0.1.jar,commons-codec-1.10-1.jar 在build.gradle添加 co ...
- RFS自动化测试(一)
RFS 即 Robot Framework + Selenium RFS 的安装 1. python https://www.python.org/ RF框架是基于python的,所以要先安装有pyt ...
- SQL系列学习 存储过程&事物语法
/*学习事物基本语法*/ /*增加课室名的唯一索引*/ ALTER table class add constraint uni_ClassName unique(name) /*创建存储过程,其中增 ...
- Android(java)学习笔记157:开源框架的文件上传(只能使用Post)
1.文件上传给服务器,服务器端必然要写代码进行支持,如下: 我们新建一个FileUpload.jsp的动态网页,同时我们上传文件只能使用post方式(不可能将上传数据拼凑在url路径下),上传数据Ap ...
- iview table 普通表格样式
iview table 普通表格样式 https://run.iviewui.com/UvLFPMb0 <template> <table> <thead> < ...
- integer to roman leetcode c++实现
Given an integer, convert it to a roman numeral. Input is guaranteed to be within the range from 1 t ...
- ES6 第五章 字符串的新增方法 具体参照 http://es6.ruanyifeng.com
1.FormCodePoint 对象方法 用于从 Unicode 码点返回对应字符,可以识别原来es5不能识别的大于0xFFFF的码点. String.fromCodePoint(0x20BB7) / ...