洛谷 Towers

题目描述

Little Vasya has received a young builder’s kit. The kit consists of several wooden bars, the lengths of all of them are known. The bars can be put one on the top of the other if their lengths are the same.

Vasya wants to construct the minimal number of towers from the bars. Help Vasya to use the bars in the best way possible.

输入格式

The first line contains an integer �N ( 1<=�<=10001<=N<=1000 ) — the number of bars at Vasya’s disposal. The second line contains �N space-separated integers ��li​ — the lengths of the bars. All the lengths are natural numbers not exceeding 10001000 .

输出格式

In one line output two numbers — the height of the largest tower and their total number. Remember that Vasya should use all the bars.

题意翻译

题面描述

Little Vasya 收到了一个来自青年建筑师的盒子,盒子里有 �n(1≤�≤10001≤n≤1000)条木头。现在他知道每条木头的长度,如果有两根木头长度一致,则他可以把其中一条放在另一条的顶部。

Vasya 想知道用木头建立的塔的最小数量。帮助 Vasya 以最好的方式使用这些木头(每根木头都要用上)。

输入格式

第一行:�n。

第二行:每条木头的长度(小于 10001000 的自然数)。

输出格式

最大塔的高度(某塔叠放木头数量)及其塔的总数。记住,Vasya 应该利用所有的木头。

输入输出样例

输入 #1复制

3
1 2 3

输出 #1复制

1 3

输入 #2复制

4
6 5 6 7

输出 #2复制

2 3

桶排序

代码如下:

#include<bits/stdc++.h>
using namespace std;
int a[1005];
int main(){
	int n,i,maxn,cnt,x;
	cin>>n;
	for(i=1;i<=n;i++){
		cin>>x;
		a[x]++;
	}
	maxn=cnt=0;
	for(i=1;i<=1000;i++){
		if(maxn<a[i]) maxn=a[i];
		if(a[i]!=0) cnt++;
	}
	cout<<maxn<<" "<<cnt;
	return 0;
}

拜拜! 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值