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. postgre sql 字符串转为integer类型

    select cast(setting_value as integer) from ud_organization_setting. select cast('123123' as integer) ...

  2. postgresql sql修改表,表字段

    1.更改表名 alter table 表名 rename to 新表名 2.更改字段名 alter table 表名 rename 字段名 to 新字段名 3.增加列 ALTER TABLE ud_w ...

  3. mysql - 编码

    show variables like 'character%'; 通过以上命令可以查询编码情况, 不过,在安装的时候,建议选择‘gbk’这类中文编码, 如果选择的是utf8,则在处理的过程中需要进行 ...

  4. Maven搭建Spring+Struts2+Hibernate项目详解

    http://www.bubuko.com/infodetail-648898.html

  5. AFN的坑--NSCachedURLResponse缓存

    网络正常的情况下,如果服务器宕机或者数据库出错,会造成访问服务器报错的情况,一般报错的内容是:无法连接到服务器或者其它错误.且服务器 修复后,仍然报错.经过排查,终于找出了原因所在:AFNetwork ...

  6. Swift 中 Selector 方法的访问权限控制问题

    今天用Swift写了个视图,在视图上加个手势,如下所示: panGestureRecognizer = UIPanGestureRecognizer(target: self, action: &qu ...

  7. JAVA开发环境 - 环境变量及配置

    JDK是什么?JRE是什么? JRE(Java Runtime Environment):Java运行环境: JDK(Java Development Kit):Java开发工具包,里面已经包含JRE ...

  8. SGU 207.Robbers

    题意: 有m(m<=10^4)个金币分给n(n<=1000)个人,第i个人期望得到所有金币的xi/y,现在给分给每个人一些金币ki使得∑|xi/y-ki/m|最小. Solution: 首 ...

  9. javascript——可以判断值的类型的函数

    function classof(o){ return Object.prototype.toString.call(0).slice(8,-1); } Function.prototype.getN ...

  10. spring + maven +testng 测试常见依赖包问题

    java.lang.ClassNotFoundException: org.apache.commons.dbcp.BasicDataSource解决方法:添加缺少的jar包:commons-coll ...