codeforces 37A Towers

本篇介绍了一道编程题目,任务是使用给定数量的木条构造尽可能高的塔,并且要达到塔的数量最少。通过输入不同长度的木条,程序会输出最高的塔的高度以及塔的总数。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

点击打开链接

A. Towers
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

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.

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.

Examples
input
3
1 2 3
output
1 3
input
4
6 5 6 7
output
2 3

题意:给出n个栅栏,相同长度的叠放在一起,求最大的塔的高度及有多少个塔.
#include<stdio.h>
#include<set>
#include<map>
#include<algorithm>
using namespace std;
int main()
{
    map<int,int>ff;
    set<int>ss;
    int n,s[1010];
    scanf("%d",&n);
    for(int i=0;i<n;i++)
    {
        scanf("%d",&s[i]);
        ff[s[i]]++;
        ss.insert(s[i]);
    }
    int ma=0;
    for(int i=0;i<n;i++)
    {
        ma=max(ma,ff[s[i]]);
    }
    printf("%d %d\n",ma,ss.size());
    return 0;
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值