A. Towers
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard outputLittle 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.
Input
The first line contains an integer N (1 ≤ 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 1000.
Output
In one line output two numbers — the height of the largest tower and their total number. Remember that Vasya should use all the bars.
Sample test(s)
input
3 1 2 3
output
1 3
input
4 6 5 6 7
output
2 3
相同长度的木棒可以堆积成塔,所以直接用计数表来存放某长度的木棒数就好
刷一遍读入,刷一遍读出。
#include <cstdio>
#include <vector>
#include <string>
#include <memory>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
int hs[1001];
int main()
{
int N;cin>>N;
memset(hs,0,sizeof hs);
int max=0;
for(int i=0;i<N;i++)
{
int a; cin>>a;
hs[a]++;
if(a>max)max=a;
}
int maxh=0,num=0;
for(int i=1;i<=max;i++)
{
if(hs[i])num++;
if(hs[i]>maxh)maxh=hs[i];
}
cout<<maxh<<" "<<num<<endl;
return 0;
}

本文介绍了一种使用计数表解决木棒堆叠问题的方法,旨在帮助小瓦沙合理利用所有木棒构建最小数量的最高塔。

253

被折叠的 条评论
为什么被折叠?



