CF BeautifulPaintings HPU 第13周练习

BeautifulPaintings

Time Limit:1000MS     Memory Limit:262144KB     64bit IO Format:%I64d & %I64u

Submit Status

Description

Thereare n picturesdelivered for the new exhibition. The i-thpainting has beauty ai.We know that a visitor becomes happy every time he passes from a painting to amore beautiful one.

Weare allowed to arranged pictures in any order. What is the maximum possiblenumber of times the visitor may become happy while passing all pictures fromfirst to last? In other words, we are allowed to rearrange elements of a inany order. What is the maximum possible number of indices i (1 ≤ i ≤ n - 1),such that ai + 1 > ai.

Input

Thefirst line of the input contains integer n (1 ≤ n ≤ 1000) —the number of painting.

Thesecond line contains the sequence a1, a2, ..., an (1 ≤ ai ≤ 1000),where ai meansthe beauty of the i-thpainting.

Output

Printone integer — the maximum possible number of neighbouring pairs, such that ai + 1 > ai,after the optimal rearrangement.

Sample Input

Input

5
20 30 10 50 40

Output

4

Input

4
200 100 100 200

Output

2

 

题意:给你一组数字,问能够组成多少对a[i+1]>a[i]

 

思路:引用一个标记数组,对已经参与比较的a[i]进行标记,最后统计即可。

 

 

参考代码:

 

/*=============================AC情况===============================*/
/*题目网址:   */
/*时间: */
/*心得:  */

#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<algorithm>
#define G 1008

using namespace std;

int main() {
	int n,a[G],vis[G];
	int ans;
	while(scanf("%d",&n)!=EOF) {
		ans=0;
		memset(vis,false,sizeof(vis));
		for(int j=0; j<n; j++)
			scanf("%d",&a[j]);
		sort(a,a+n);
		for(int j=0; j<n-1; j++) {
			for(int k=j+1; k<=n-1; k++) {
				if(vis[j+1]==false&&a[j+1]>a[j]) {
					vis[j+1]=true;
					ans++;
					break;
				}
			}
		}
		printf("%d\n",ans);
	}
	return 0;
}

/*********************************测试数据*********************************


**************************************************************************/

一个for 搞不定的代码:

/*=============================AC情况===============================*/
/*题目网址:   */
/*时间: */
/*心得:  */

#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<algorithm>
#define G 1008

using namespace std;

int main() {
	int n,a[G],vis[G];
	int ans;
	while(scanf("%d",&n)!=EOF) {
		ans=0;
		memset(vis,false,sizeof(vis));
		for(int j=0; j<n; j++)
			scanf("%d",&a[j]);
		sort(a,a+n);
		for(int j=0; j<n-1; j++) {
			if(vis[j+1]==false&&a[j+1]>a[j]) {
				vis[j+1]=true;
				ans++;
			}
		}
		printf("%d\n",ans);
	}
	return 0;
}

/*********************************测试数据*********************************


**************************************************************************/


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值