注意考虑排序和相同项剔除

1094 : Lost in the City

时间限制:10000ms
单点时限:1000ms
内存限制:256MB
描述
Little Hi gets lost in the city. He does not know where he is. He does not know which direction is north.

Fortunately, Little Hi has a map of the city. The map can be considered as a grid of N*M blocks. Each block is numbered by a pair of integers. The block at the north-west corner is (1, 1) and the one at the south-east corner is (N, M). Each block is represented by a character, describing the construction on that block: ‘.’ for empty area, ‘P’ for parks, ‘H’ for houses, ‘S’ for streets, ‘M’ for malls, ‘G’ for government buildings, ‘T’ for trees and etc.

Given the blocks of 3*3 area that surrounding Little Hi(Little Hi is at the middle block of the 3*3 area), please find out the position of him. Note that Little Hi is disoriented, the upper side of the surrounding area may be actually north side, south side, east side or west side.

输入
Line 1: two integers, N and M(3 <= N, M <= 200).
Line 2~N+1: each line contains M characters, describing the city’s map. The characters can only be ‘A’-‘Z’ or ‘.’.
Line N+2~N+4: each line 3 characters, describing the area surrounding Little Hi.

输出
Line 1~K: each line contains 2 integers X and Y, indicating that block (X, Y) may be Little Hi’s position. If there are multiple possible blocks, output them from north to south, west to east.

import java.lang.reflect.Array;
import java.util.*;/*** Created by 95112 on 2/26/2018.*/
public class LostInTheCity {public static void main(String[] args){Scanner scanner = new Scanner(System.in);int N,M;char[][] map;String input;N = scanner.nextInt();M = scanner.nextInt();scanner.nextLine();map = new char[N][M];for (int i = 0 ; i < N; i++) {input = scanner.nextLine();map[i] =  input.toCharArray();}char[][] location = new char[3][3];for (int i = 0 ; i < 3; i++){input = scanner.nextLine();location[i] = input.toCharArray();}char[][] l2,l3,l4;l2 = new char[3][3];l3 = new char[3][3];l4 = new char[3][3];for (int i = 0; i< 3; i++)for(int j = 0 ; j < 3 ; j++){char tmp = location[i][j];l2[2-j][i] = tmp;l3[2-i][2-j] = tmp;l4[j][2-i] = tmp;}ArrayList<int[]> answers = new ArrayList<>();answers.addAll(find(map,location));answers.addAll(find(map,l2));answers.addAll(find(map,l3));answers.addAll(find(map,l4));Comparator<int[]> comparator = new Comparator<int[]>() {@Overridepublic int compare(int[] o1, int[] o2) {if (o1==null)return 1;else if (o2 == null)return -1;else {if (o1[0] < o2[0])return -1;else if (o1[0] > o2[0])return 1;else {if (o1[1] < o2[1])return -1;elsereturn 1;}}}};answers.sort(comparator);HashMap<Integer,ArrayList<Integer>> hashmap = new HashMap<>();for (int[] answer:answers){if (!hashmap.containsKey(answer[0])) {System.out.println(answer[0] + " " + answer[1]);ArrayList<Integer> arrayList = new ArrayList<>();arrayList.add(answer[1]);hashmap.put(answer[0],arrayList);}else{ArrayList<Integer> arrayList = hashmap.get(answer[0]);if (!arrayList.contains(answer[1])){System.out.println(answer[0] + " " + answer[1]);arrayList.add(answer[1]);hashmap.put(answer[0],arrayList);}}}}private static ArrayList<int[]> find(char[][] map, char[][] around){int N,M;N = map.length;M = map[0].length;ArrayList<int[]> answers  = new ArrayList<>();for (int i = 0 ; i < N-2;i++)for (int j = 0 ; j < M-2; j++){if (map[i][j] == around[0][0]){boolean isError = false;for (int x = 0;x <3 ;x++) {if (isError)break;for (int y = 0; y < 3; y++) {if (map[i + x][j + y] != around[x][y]) {isError = true;}}}if (isError == false) {int[] answer = new int[2];answer[0] = i+2;answer[1] = j+2;answers.add(answer);}}}return answers;}
}

微软苏州校招笔试 12月27日 By Java相关推荐

  1. hihoCoder 1095 HIHO Drinking Game 微软苏州校招笔试 12月27日

    由game规则可以看出,T越大超出d的可能性越大,对小ho越有利,其实我是通过打表才看出来这个单调性的==. 对T进行二分搜索,[0,K+1],因为如果N=1,那么应该有T=K+1,小ho才可以获胜. ...

  2. hihocoder #1103 : Colorful Lecture Note微软苏州校招笔试 1月10日(字符串处理+栈)

    #1103 : Colorful Lecture Note 时间限制:10000ms 单点时限:1000ms 内存限制:256MB 描述 Little Hi is writing an algorit ...

  3. 线上会议丨中国中文信息学会2020学术年会将于12月27日举行

    会议时间 2020年12月27日 北京 会议官网 http://www.cipsc.org.cn/annual2020 扫码进入会议官网 扫码观看直播 特邀报告 按报告时间排序 专题研讨

  4. web实践 例会12月27日

    12月27日 项目进度表: 今日工作: 1.      首先是小组开展例会,确定选题和进行基本功能分析. 2.      确定第一阶段的选做内容为安全性分析. 3.      小组分工如下 a)    ...

  5. 实战 | 深度学习轻松学:如何用可视化界面来部署深度学习模型 转载 2017年12月27日 00:00:00 109 翻译 | AI科技大本营 参与 | 王赫 上个月,我有幸结识了 DeepCogn

    实战 | 深度学习轻松学:如何用可视化界面来部署深度学习模型 转载 2017年12月27日 00:00:00 标签: 109 编辑 删除 翻译 | AI科技大本营 参与 | 王赫 上个月,我有幸结识了 ...

  6. 百度元宇宙产品“希壤”将于12月27日发布

    近日,百度宣布将于12月27日发布元宇宙产品"希壤" ,届时百度 Create 2021(百度 AI 开发者大会)将在希壤 APP 举办. 据介绍,"希壤"AP ...

  7. 三周第三次课(12月27日)

    三周第三次课(12月27日) 3.7 su命令 su 切换用户 whoami id su -aming su aming 切换用户,但是没有切换家目录 su - -c "touch /tmp ...

  8. 电信网通证实台湾地震影响内地访问国际网站(12月27日)

    <iframe align="top" marginwidth="0" marginheight="0" src="http ...

  9. 【历史上的今天】12 月 27 日:第一台计算机背后的女性们;Box 创始人出生;开普勒诞生

    整理 | 王启隆 透过「历史上的今天」,从过去看未来,从现在亦可以改变未来. 今天是 2022 年 12 月 27 日,在 2002 年的今天,南水北调工程开工典礼举行.南水北调是一个可持续发展的工程 ...

  10. 电信网通证实台湾地震影响内地访问国际网站(12月27日) 1

    电信网通证实台湾地震影响内地访问国际网站 http://www.sina.com.cn 2006年12月27日 09:39 东方网   中国国际海底光缆网络 中美六家运营商正在共同建设连接中国和美国的 ...

最新文章

  1. mysql返回查询条件_mysql条件查询
  2. 腾讯面试题:创建索引时,你会怎么考虑呢?(看完你就能和面试官谈人生了)
  3. RNAseq-GO、biomaRt转换ID
  4. 草履虫纳米机器人_Nature:看不见的外科医生——比头发丝还小的微型“机器人大军”正在走来...
  5. 3.Hadoop的学习(ubuntu安装配置jdk)
  6. Java开发手册——嵩山版(清幽现云山,虚静出内功)
  7. SQL读书笔记_With Clause的注意事项
  8. 【转】学习笔记:GoogLeNet
  9. 微软云计算动态登陆“MSDN论坛好帮手”
  10. Java自动类型转换和强制类型转换
  11. POJ1149PIGS
  12. h5聊天工具的开发过程及思路
  13. idea连接Mysql报错
  14. Nagios监控数据脚本记录一下。
  15. Vue_(组件)实例属性
  16. 人工智能——皇帝的新脑还是人类的终结(学习笔记)
  17. Skyline软件二次开发初级——6如何在WEB页面中的三维地图上进行坐标和方向计算...
  18. PDF文档页面如何重新排版?
  19. vue 怎么销毁dom_Vue 中如何转移 Dom ?
  20. 运营必备九大互联网思维

热门文章

  1. IBM WMB 使用方法
  2. 怎么清楚计算机硬盘搜索记录,如何去除电脑硬盘删除痕迹
  3. 开心网程炳皓:早期创业公司应该做一根针
  4. 《互联网周刊》发布2019快时尚品牌排行榜
  5. PMI采购MogaFX经理人指数是什么
  6. 论文投稿排版时,Word首页插入连续分节符,后面的内容自动到下一页
  7. ROS中gazebo工具学习(使用gazebo加载机器人模型)
  8. ERP系统实施之入门
  9. word怎么删除参考文献的横线_Word2010利用尾注做参考文献时如何删除尾注中的横线...
  10. access如何求平均单价_ACCESS中计算日均值