HDOJ(HDU) 2192 MagicBuilding(用Java的Map做了下)
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做了下)的更多相关文章
- java使用Map做缓存你真的用对了吗?弱引用WeakHashMap了解一下
目录 关于缓存我们应该考虑什么?-intsmaze WeakHashMap弱引用-intsmaze 线程安全问题-intsmaze Collections-intsmaze ThreadLocal-i ...
- hdu 2192 MagicBuilding
Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission( ...
- HDOJ/HDU 1251 统计难题(字典树啥的~Map水过)
Problem Description Ignatius最近遇到一个难题,老师交给他很多单词(只有小写字母组成,不会有重复的单词出现),现在老师要他统计出以某个字符串为前缀的单词数量(单词本身也是自己 ...
- HDOJ/HDU 1113 Word Amalgamation(字典顺序~Map)
Problem Description In millions of newspapers across the United States there is a word game called J ...
- 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 ...
- 错误: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 ...
- Java中Map常用方法总结以及遍历方式的汇总
一.整理: 看到array,就要想到角标. 看到link,就要想到first,last. 看到hash,就要想到hashCode,equals. 看到tree,就要想到两个接口.Comparable, ...
- Java 基础 Map 练习题
第一题 (Map)利用Map,完成下面的功能: 从命令行读入一个字符串,表示一个年份,输出该年的世界杯冠军是哪支球队.如果该 年没有举办世界杯,则输出:没有举办世界杯. 附:世界杯冠军以及对应的夺冠年 ...
- java 遍历map 方法 集合 五种的方法
package com.jackey.topic; import java.util.ArrayList;import java.util.HashMap;import java.util.Itera ...
随机推荐
- C#中的Dictionary字典类介绍
Dictionary字典类介绍 必须包含名空间System.Collection.Generic Dictionary里面的每一个元素都是一个键值对(由二个元素组成:键和值) 键必须是 ...
- (九)打印机驱动设置—USB接口的设置
佳博打印机代理商淘宝店https://shop107172033.taobao.com/index.htm?spm=2013.1.w5002-9520741823.2.Sqz8Pf 在此店购买的打印机 ...
- oracle触发器调试
1.如下图位置点击触发器,会出现调试窗口 2.执行编译并调试 3.点击小虫,将画红位置,加入会触发此触发器的语句.如果触发器执行成功,不会出现第4个图,不成功,会出现数据调试信息,具体报错位置会定位到 ...
- 在万网虚拟主机上部署MVC5
参考 要想部署mvc,需要把一些mvc用到的全局程序集改为本地部署,通过N次试验,终于搞定. 特写个备忘录,免得以后忘了. 首先更改web.config,在里面加上 <system.web> ...
- java_设计模式_模板方法模式_Template Method Pattern(2016-08-11)
定义: 定义一个操作中算法的骨架,而将一些步骤延迟到子类中,使得子类可以不改变算法的结构即可重定义该算法中的某些特定步骤.这里的算法的结构,可以理解为你根据需求设计出来的业务流程.特定的步骤就是指那些 ...
- 数据挖掘相关的10个问题[ZZ]
NO.1 Data Mining 和统计分析有什么不同? 硬要去区分Data Mining和Statistics的差异其实是没有太大意义的.一般将之定义为Data Mining技术的CART.CHAI ...
- 用css3实现鼠标移进去当前亮其他变灰
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/ ...
- 原生javascript写的侧栏跟随效果
浏览网站时经常看到有的网站上,当一个页面很长的时候,设定侧栏内容会跟随滚动条滚动,我们把这种效果叫做“侧栏跟随滚动”.这种特效对提高网站浏览量.文章点击率.广告点击量都有一定效果. 侧栏跟随滚动的实现 ...
- JS call和apply用法(转)
每个JavaScript函数都会有很多附属的(attached)方法,包括toString().call()以及apply().听起来,你是否会 感到奇怪,一个函数可能会有属于它自己的方法,但是记住, ...
- JavaScript多线程初步学习
一.多线程理解 首先,我们要理解什么是多线程,百度百科上说:多线程(英语:multithreading),是指从软件或者硬件上实现多个线程并发执行的技术.具有多线程能力的计算机因有硬件支持而能够在同一 ...