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. 在ec2上创建root用户,并使用root 通过Xshell远程登录aws云服务器

    1.根据官网提供的方法登录连接到EC2服务器(官网推荐windows用户使用PUTTY连接) 2. 创建root的密码,输入如下命令: sudo passwd root 3.然后会提示你输入new p ...

  2. C#获取类中所有方法

    var t = typeof(HomeController); //获取所有方法 System.Reflection.MethodInfo[] methods = t.GetMethods(); // ...

  3. solve_lock-1024-大功告成

    create or replace procedure solve_lock_061203(v_msg out varchar2) as  v_sql varchar2(3000); --定义 v_s ...

  4. 11g 创建asm磁盘组

    [root@Oracle11g ~]# fdisk -l Disk /dev/sda: 21.4 GB, 21474836480 bytes255 heads, 63 sectors/track, 2 ...

  5. [总结]RTMP流媒体技术零基础学习方法

    本文主要总结一些我在学习RTMP流媒体技术过程中积累的经验.也为后来学习RTMP流媒体技术的人们一个参考.本文力图从简到难,循序渐进的介绍RTMP流媒体技术的方方面面,先从应用说起,逐步深化剖析相关工 ...

  6. android查看真机中的数据库

    0.在有网的前提下1.安装 Android Studio,Lantern,Chrome浏览器2.在在githab上搜索stetho,打开第一个facebook/stetho3.在Gradle Scri ...

  7. Vijos P1521 跳舞 贪心

    本来想找一道网络流的题来着,结果这道题越看越不对劲,总觉得这题存在不用网络流的解法 看了题解区以后坚定了自己的猜想 #include <cstdio> #include <cstri ...

  8. Codeforces 527E Data Center Drama(欧拉回路)

    题意: 给定一个无向图连通图,把这个的无向边变成有向边,并添加最少的有向边使这个图每个结点的出度为偶数. Solution: 题目很长,并且很多条件说的不太直接,确实不太好懂. 首先先看得到的无向图, ...

  9. skip-grant-tables的作用

    skip-grant-tables:非常有用的mysql启动参数(不启动grant-tables授权表) skip-grant-tables:非常有用的mysql启动参数   介绍一个非常有用的mys ...

  10. spring mvc easyui tree 异步加载树

    使用spring mvc 注解 异步加载一棵树 jsp: <ul id="orgInfoTree"></ul> $(function(){ loadOrgT ...