次数nullhdu2192(MagicBuilding 贪心)

本文介绍了一个关于如何计算最少数量的特殊建筑的问题。通过输入不同大小的建筑物集合,算法能够找出能够形成最少数量的特殊建筑组合的方法。文章还提供了一段实现该算法的C语言代码。

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

文章结束给大家来个程序员笑话:[M]

    

Problem Description

    

As the increase of population, the living space for people is becoming smaller and smaller. In MagicStar the problem is much worse. Dr. Mathematica is trying to save land by clustering buildings and then we call the set of buildings MagicBuilding. Now we can treat the buildings as a square of size d, and the height doesn't matter. Buildings of d1,d2,d3....dn can be clustered into one MagicBuilding if they satisfy di != dj(i != j).
Given a series of buildings size , you need to calculate the minimal numbers of MagicBuildings that can be made. Note that one building can also be considered as a MagicBuilding.
Suppose there are five buildings : 1, 2, 2, 3, 3. We make three MagicBuildings (1,3), (2,3), (2) .And we can also make two MagicBuilding :(1,2,3), (2,3). There is at least two MagicBuildings obviously.

    

 

    

Input

    

The first line of the input is a single number t, indicating the number of test cases.
Each test case starts by n (1≤n≤10^4) in a line indicating the number of buildings. Next n positive numbers (less than 2^31) will be the size of the buildings.
    每日一道理
只有启程,才会到达理想和目的地,只有拼搏,才会获得辉煌的成功,只有播种,才会有收获。只有追求,才会品味堂堂正正的人。

    

 

    

Output

    

For each test case , output a number perline, meaning the minimal number of the MagicBuilding that can be made.

    

 

    

Sample Input
2 1 2 5 1 2 2 3 3
 

    

Sample Output
1
2

 

    标题意思是:求出最少要建的栋数(一栋可以有很多房);

    思路:算出最多涌现的次数房的个数.

 

#include<stdio.h>
int main()
{
    int t,n,a[10005]e,i,j,sum;
    scanf("%d",&t);
    while(t--)
    {
        scanf("%d",&n);
        
        for(i=0;i<n;i++)
        scanf("%d",&a[i]);
        sum=0;
        for(i=0;i<n;i++)
        {
            e=1;
            for(j=i+1;j<n;j++)
            if(a[i]==a[j])
            {
               e++;
            }
            if(e>sum)//这房涌现的次数
            sum=e;
           
        }
        printf("%d\n",sum);
    }
}

    
 

文章结束给大家分享下程序员的一些笑话语录: 问路
有一个驾驶热气球的人发现他迷路了。他降低了飞行的高度,并认出了地面 上的一个人。他继续下降高度并对着那个人大叫,“打扰一下,你能告诉我我 在哪吗?”
下面那个人说:“是的。你在热气球里啊,盘旋在 30 英尺的空中”。
热气球上的人说:“你一定是在 IT 部门做技术工作”。
“没错”,地面上的人说到,“你是怎么知道的?”
“呵呵”,热气球上的人说,“你告诉我的每件事在技术上都是对的,但对都没 有用”。
地面上的人说,“你一定是管理层的人”。
“没错”,热气球上的人说,“可是你是怎么知道的?”
“呵呵”,地面上的那人说到,“你不知道你在哪里,你也不知道你要去哪,你 总希望我能帮你。你现在和我们刚见面时还在原来那个地方,但现在却是我 错了”。

--------------------------------- 原创文章 By 次数和null ---------------------------------

转载于:https://www.cnblogs.com/jiangu66/archive/2013/05/23/3095448.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值