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

其实说了这么多,就是找出现次数最多的那个数。

练习了下Map的使用。也可以不用Map的。

import java.util.Map;
import java.util.Scanner;
import java.util.TreeMap; public class Main{ public static void main(String[] args) {
Scanner sc =new Scanner(System.in);
int t =sc.nextInt();
while(t-->0){
Map<Integer,Integer> map = new TreeMap<Integer, Integer>();
int n=sc.nextInt();
int m[] = new int[n];
for(int i=0;i<n;i++){
m[i] = sc.nextInt();
if(map.get(m[i])==null){
map.put(m[i], 1);
}else{
map.put(m[i], map.get(m[i])+1);
}
}
int max=0;
for(int i=0;i<n;i++){
if(map.get(m[i])>max){
max=map.get(m[i]);
}
}
System.out.println(max);
}
}
}

HDOJ(HDU) 2192 MagicBuilding(用Java的Map做了下)的更多相关文章

  1. java使用Map做缓存你真的用对了吗?弱引用WeakHashMap了解一下

    目录 关于缓存我们应该考虑什么?-intsmaze WeakHashMap弱引用-intsmaze 线程安全问题-intsmaze Collections-intsmaze ThreadLocal-i ...

  2. hdu 2192 MagicBuilding

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

  3. HDOJ/HDU 1251 统计难题(字典树啥的~Map水过)

    Problem Description Ignatius最近遇到一个难题,老师交给他很多单词(只有小写字母组成,不会有重复的单词出现),现在老师要他统计出以某个字符串为前缀的单词数量(单词本身也是自己 ...

  4. HDOJ/HDU 1113 Word Amalgamation(字典顺序~Map)

    Problem Description In millions of newspapers across the United States there is a word game called J ...

  5. HDOJ/HDU 1075 What Are You Talking About(字符串查找翻译~Map)

    Problem Description Ignatius is so lucky that he met a Martian yesterday. But he didn't know the lan ...

  6. 错误:java.util.Map is an interface, and JAXB can't handle interfaces.

    问题: 在整合spring+cxf时报错java.util.Map is an interface, and JAXB can't handle interfaces. 解决方法: 将服务端的serv ...

  7. Java中Map常用方法总结以及遍历方式的汇总

    一.整理: 看到array,就要想到角标. 看到link,就要想到first,last. 看到hash,就要想到hashCode,equals. 看到tree,就要想到两个接口.Comparable, ...

  8. Java 基础 Map 练习题

    第一题 (Map)利用Map,完成下面的功能: 从命令行读入一个字符串,表示一个年份,输出该年的世界杯冠军是哪支球队.如果该 年没有举办世界杯,则输出:没有举办世界杯. 附:世界杯冠军以及对应的夺冠年 ...

  9. java 遍历map 方法 集合 五种的方法

    package com.jackey.topic; import java.util.ArrayList;import java.util.HashMap;import java.util.Itera ...

随机推荐

  1. 常用的 css 命名规则

    头:header 内容:content/container 尾:footer 导航:nav 侧栏:sidebar 栏目:column 页面外围控制整体布局宽度:wrapper 左右中:left rig ...

  2. HTML - 键盘事件

    Keyboard 事件 onkeydown: 在用户按下按键时触发. onkeypress: 在用户敲击按钮时触发. onkeyup: 当用户释放按键时触发. 示例 <!DOCTYPE html ...

  3. PHP 进行统一邮箱登陆的代理实现(swoole)

    在工作的过程中,经常会有很多应用有发邮件的需求,这个时候需要在每个应用中配置smtp服务器.一旦公司调整了smtp服务器的配置,比如修改了密码等,这个时候对于维护的人员来说要逐一修改应用中smtp的配 ...

  4. Xaml中的资源(1 样式)

    <Window x:Class="MyResoures.MainWindow" xmlns="http://schemas.microsoft.com/winfx/ ...

  5. JS获取屏幕各种高

    <script language="javascript"> var h = ""; h += " 网页可见区域宽:"+ doc ...

  6. SGU 149. Computer Network

    时间限制:0.25s 空间限制:4M: 题意: 给出一颗n(n<=10000)个节点的树,和n-1条边的长度.求出这棵树每个节点到最远节点的距离: Solution: 对于一个节点,我们可以用D ...

  7. WPF之核心面板(容器)控件简单介绍

    一.Canvas 1.官方表述:定义一个区域,在该区域中可以使用相对于该区域的坐标显式定位子元素. 2.对于canvas 的元素的位置,是靠控件的大小及Canvas.Top.Canvas.Left.C ...

  8. <input>标签

    一. 上传图片: type="file":上传文件​ accept:选择上传的种类,图片或者是视频(/png只能上传png格式的图片) ​multiple="multip ...

  9. jQuery--引入,基本语法,以及常用事件

    一.初识jQuery jQuery是一个JavaScript函数库.主要包含的功能有:HTML元素的选取.操作,CSS操作,HTML事件函数,JavaScript特效和动画,HTML DOM遍历和修改 ...

  10. 定时器内部的this

    今天写了个例子遇见的: timer1=setTimeout(function(){ $(this).next().css("display","none") } ...