hdu 2192 MagicBuilding(简单的水题,sort排序)

MagicBuilding

Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)

Total Submission(s): 1314    Accepted Submission(s): 599

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

Author

scnu

题意:

就是给定几组数据,把这些数据进行合并,并且合并的时候,一个组里面的没有两个数值是相同的,判断最少是几组数据?

难点:

如何判定是几组数据?

解决办法:

就是找出相同的数最多的即可。

代码如下 :

<span style="font-size:14px;">#include<stdio.h>
#include<algorithm>
using namespace std;
int a[10010];
int main()
{
	int t,i,n;
	scanf("%d",&t);
	while(t--)
	{
		scanf("%d",&n);
		for(i=0;i<n;i++)
		{
			scanf("%d",&a[i]);
		}
		sort(a,a+n);
		int sum=1;
		int Max=1;
		int m=a[0];
		for(i=1;i<n;i++)
		{
			if(a[i]==m)
			{
				++sum;
			}
			else
			{
				m=a[i];
				sum=1;
			}
			if(Max<sum)
			Max=sum;
		}
		printf("%d\n",Max);
	}
	return 0;
}</span>
时间: 2024-10-18 10:06:00

hdu 2192 MagicBuilding(简单的水题,sort排序)的相关文章

HDU 1840 Equations (简单数学 + 水题)(Java版)

Equations 题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1840 --每天在线,欢迎留言谈论. 题目大意: 给你一个一元二次方程组,a(X^2) + b(X) + c = 0 .求X解的个数. 思路: 分别讨论二次方程与一次方程的情况,再特殊处理下 a = b = c = 0 的情况. 感想: 是时候该水水题了. Java AC代码: 1 import java.math.*; 2 import java.util.Scanner; 3

HDU Senior&#39;s Gun (水题)

题意:给n把枪,m个怪兽,每把枪可消灭1怪兽,并获得能量=枪的攻击力-怪兽的防御力.求如何射杀能获得最多能量?(不必杀光) 思路:用最大攻击力的枪杀防御力最小的怪兽明显可获得最大能量.如果每把枪都去射杀刚好1点能量都拿不到的怪物,那简直等于把枪全丢掉. 1 //#pragma comment(linker,"/STACK:102400000,102400000") 2 #include <iostream> 3 #include <stdio.h> 4 #inc

HDU 5590 ZYB&#39;s Biology 水题

ZYB's Biology Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=5590 Description ZYB(ZJ−267)在NOIP拿到600分之后开始虐生物题,他现在扔给你一道简单的生物题:给出一个DNA序列和一个RNA序列,问它们是否配对. DNA序列是仅由A,C,G,T组成的字符串,RNA序列是仅由A,C,G,U组成的字符串. DNA和RNA匹配当且仅当每

hdu 1999 不可摸数 水题。

不可摸数 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 7966    Accepted Submission(s): 2024 Problem Description s(n)是正整数n的真因子之和,即小于n且整除n的因子和.例如s(12)=1+2+3+4+6=16.如果任何数m,s(m)都不等于n,则称n为不可摸数. Input 包

蓝桥杯 算法训练 最小乘积(基本型) (水题,排序)

算法训练 最小乘积(基本型) 时间限制:1.0s   内存限制:512.0MB 问题描述 给两组数,各n个. 请调整每组数的排列顺序,使得两组数据相同下标元素对应相乘,然后相加的和最小.要求程序输出这个最小值. 例如两组数分别为:1 3 -5和-2 4 1 那么对应乘积取和的最小值应为: (-5) * 4 + 3 * (-2) + 1 * 1 = -25 输入格式 第一个行一个数T表示数据组数.后面每组数据,先读入一个n,接下来两行每行n个数,每个数的绝对值小于等于1000. n<=8,T<=

杭电(hdu)2053 Switch Game 水题

Switch Game Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 13113    Accepted Submission(s): 7970 Problem Description There are many lamps in a line. All of them are off at first. A series of o

hdu 4847 Wow! Such Doge! 水题

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4847 统计文本中一共有多少个“Doge” 水题 #include <cstring> #include <cstdlib> #include <cstring> #include <cmath> #include <algorithm> #include <iostream> #include <cstdio> #includ

HDU 5578 Friendship of Frog 水题

Friendship of Frog Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=5578 Description N frogs from different countries are standing in a line. Each country is represented by a lowercase letter. The distance betwee

hdu 5532 Almost Sorted Array (水题)

Almost Sorted Array Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 262144/262144 K (Java/Others)Total Submission(s): 8541    Accepted Submission(s): 1982 Problem Description We are all familiar with sorting algorithms: quick sort, merge sort