Codeforces 651B Beautiful Paintings
来源:互联网 发布:二式大艇数据 编辑:程序博客网 时间:2024/05/16 04:50
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.
520 30 10 50 40
4
4200 100 100 200
2
从很久很久以前,那里有一个画展,画展有n幅画,第i幅画有一个美丽指数ai。我们知道的是,一个当游览者从一张画到一张美丽指数更高的画的时候,会变得开心。
画将会一列的排放,我们可以随意安排画的顺序。那么如果游览者以从头到尾的顺序游览的画,总共最多可以变开心多少次呢。
换而言之,我们需要将美丽指数重新排列,使得有最多的i (1 ≤ i ≤ n - 1), 符合 ai + 1 > ai. 输出符合条件的i的数目。
#include <stdio.h> #include <stdlib.h> int sort(const void* a,const void* b) { return *(int*)a-*(int*)b; } int main() { int n; int array[1000]; while(scanf("%d",&n)!=EOF){ for(int i=0;i<n;i++) scanf("%d",&array[i]); qsort(array,n,sizeof(int),sort); int now; int count=0; for(int j=0;j<=n-1;j++){ if(array[j]!=0){ now=array[j]; array[j]=0; for(int k=j+1;k<=n-1;k++) if(array[k]!=0&&array[k]>now){ count++; now=array[k]; array[k]=0; } } } printf("%d\n\n",count); } return 0; }
- codeforces--651B Beautiful Paintings
- codeforces 651B Beautiful Paintings
- CodeForces 651B Beautiful Paintings
- codeforces 651B Beautiful Paintings
- CodeForces 651B Beautiful Paintings
- 【CodeForces】651B - Beautiful Paintings
- 【CodeForces】[651B]Beautiful Paintings
- CodeForces 651B Beautiful Paintings
- CodeForces 651B Beautiful Paintings
- Codeforces 651B Beautiful Paintings
- codeforces 651B Beautiful Paintings (想法)
- codeforces 651B Beautiful Paintings【优先队列】
- Codeforces 651B Beautiful Paintings【思维】
- codeforces 651B Beautiful Paintings(贪心)
- Codeforces 651B Beautiful Paintings【贪心】
- 【CodeForces 651B】Beautiful Paintings 排序+贪心
- 【codeforces 651B - Beautiful Paintings 】 greedy(贪心)
- codeforces 651B Beautiful Paintings (思路题)
- ExecutorService 的理解与使用
- poj 1258 (kruskal)
- prototype 属性使您有能力向对象添加属性和方法 三
- javascript实现 DOM BOM
- 2016-09-23 18:45:10,950 Stage-6 map = 60%, reduce = 0%, Cumulative CPU 1740.12 sec
- Codeforces 651B Beautiful Paintings
- Retrofit如何提交json数据
- JavaScript面向对象编程之继承
- 二叉树最近公共祖先
- Instanceof和isInstance的区别
- hdu 5900 QSC and Master (区间dp)
- Java之类注意事项
- 1032. Sharing (25)
- Java 实现 Base64 加密解密