hihoCoder-Lost in the City

hihoCoder-Lost in the City

描述

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.

样例输入

8 8
...HSH..
...HSM..
...HST..
...HSPP.
PPGHSPPT
PPSSSSSS
..MMSHHH
..MMSH..
SSS
SHG
SH.

样例输出

5 4

    这个题归类为枚举,因为题目的问题规模比较小(N,M最大是200),所以暴力求解就可以。maps二维数组存储city的数据,location二维数组存储Little Hi周围的数据。(这个题目中有一个比较重要的地方就是, 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.)

    思路如下:1.在maps二维数组中找到location的中心的元素,也就是Little Hi的位置(x,y);

                      2.暴力求解时没有用网上一些同学用的旋转矩阵的方法来做,而是将location中除了中心元素外的其他8个元素按照顺时针拼接成一个字符串s1,因为在maps矩阵中(x,y)周围的元素顺序不确定,所以s1 += s1,将字符串首尾相连,组成一个备用比较的长字符串;将maps中与location中心元素相等的元素的周围8个字符也拼串为s2。因为已经比较过了中心位置的元素,其实要找到准确的Little Hi的位置就是比较s2是否在s1中出现过(利用在s1中查找子串的方法),然后取此时的(x,y)就可以了。

代码如下:


import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner input = new Scanner(System.in);
		int N = input.nextInt();
		int M = input.nextInt();
		
		char[][] maps = new char[N][M];
		for (int i = 0; i < N; i++){
			String string = input.next().trim();
			maps[i] = string.toCharArray();
		}
		
		String s1 = new String();
		char[][] location = new char[3][3];
		for (int i = 0; i < 3; i++){
			String string = input.next().trim();
			location[i] = string.toCharArray();
		}
		String temp1 = "" + location[0][0] + location[0][1] + location[0][2];
		String temp2 = "" + location[1][2] + location[2][2] + location[2][1];
		String temp3 = "" + location[2][0] + location[1][0];
		s1 = temp1 + temp2 + temp3;
		s1 += s1;
		//System.out.println(s1);
		char center = location[1][1];
		for (int i = 1; i < N - 1; i++){
			for (int j = 1; j < M - 1; j++){
				String s2 = new String();
				if (maps[i][j] == center){
					temp1 = "" + maps[i - 1][j - 1] + maps[i - 1][j] + maps[i - 1][j + 1];
					temp2 = "" + maps[i][j + 1] + maps[i + 1][j + 1] + maps[i + 1][j];
					temp3 = "" + maps[i + 1][j - 1] + maps[i][j - 1];
					s2 = temp1 + temp2 + temp3;
					//System.out.println(s2);
					for (int k = 0; k < s1.length() / 2; k++){
						String r1 = s1.substring(k, k + 8);
						if (r1.equals(s2)){
							System.out.println((i + 1) + " " + (j + 1));
							break;
						}
					}
				}
			}
		}
	}
}

 

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
根据提供的文件内容,本文将详细解析“飞行弹道仿真”的核心知识点,主要涉及MATLAB编程环境下的弹道仿真实现过程。 ### 弹道仿真概述 弹道仿真是一种通过数学模型来预测导弹、炮弹等飞行器在空中飞行轨迹的技术。在军事、航天等多个领域都有着广泛的应用。对于弹道仿真的研究不仅有助于提升武器系统的精确度,还能帮助科研人员更好地理解空气动力学原理以及飞行器的动力特性。 ### MATLAB环境下弹道仿真的实现 #### 1. **初始化参数** 在代码中,作者首先对一系列变量进行了初始化处理。这些变量包括但不限于:质量(`m`), 速度(`V`), 高度(`H`)等关键物理量。此外,还定义了一些常量如重力加速度(`g`)、空气密度(`rho_air`)等。 #### 2. **地面高度分布设定** 通过设定地面高度随距离变化的函数(`x_d` 表示水平距离,`H_d` 表示对应的高度),可以模拟不同的地形特征。这里使用了一个分段函数来表示地面高度的变化情况。 #### 3. **动态方程与运动方程** - **动态方程**:描述了导弹受到的外力作用(推力、阻力、升力)以及重力对其运动状态的影响。 - 推力(`P`)、阻力(`X`)、升力(`Y`)等参数被用于计算导弹的速度和角度变化。 - 通过积分运算更新速度、角度等状态量。 - **运动方程**:描述了导弹在三维空间中的位置变化情况。 - 包括水平方向速度(`equ4_Kinematic_x`)、垂直方向速度(`equ5_Kinematic_y`)以及姿态角(`equ6_Kinematic_Theta`)的变化。 - 这些方程同样通过积分方法进行求解。 #### 4. **控制律设计** 控制律设计是确保导弹按照预定轨迹飞行的关键环节。例如,代码中采用了简单的PID控制策略来调整导弹的姿态角。具体地: - `k_phi` 和 `k_phidiff` 分别代表比例系数和微分系数。 - 通过调整这些系数的值,可以优化导弹的飞行性能,使其更加稳定且能够准确跟踪目标。 #### 5. **数值积分方法** 为了求解动态方程与运动方程,文中采用了一种数值积分方法(`integral_to_next`)。该方法可以近似计算出导弹在下一时刻的状态量(速度、角度等)。虽然具体的实现细节没有给出,但通常这类方法基于欧拉法或者更高级的龙格-库塔法等。 ### 结论 本文通过对“飞行弹道仿真”这一主题的深入探讨,不仅详细介绍了如何使用MATLAB进行弹道仿真,而且还重点讲解了其中涉及到的重要概念和技术细节,如地面高度分布设定、动态方程与运动方程、控制律设计以及数值积分方法等。对于希望深入了解弹道仿真技术的研究者来说,本文提供了丰富的参考资料和实施指南。通过这样的仿真研究,不仅可以提高导弹等飞行器的设计精度,还能为未来航空航天技术的发展提供强有力的支持。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值