hihocoder1094 Lost in the City

在一座由N*M网格组成的虚拟城市中,小Hi迷失了方向。利用一张描绘了公园(P)、房屋(H)、街道(S)等特征的详尽地图,通过分析小Hi周围3x3区域的特定模式,本篇探讨如何确定他的确切位置,即使他无法分辨方向。通过对比地图上的各个区块,我们能够找出所有可能的小Hi所在位置。
描述

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 33 area that surrounding Little Hi(Little Hi is at the middle block of the 33 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

思路:
先找到有Hi的地方(不计算矩阵的最外圈),然后拿数据给出的Hi的3*3地图的进行四种方向的变换再和每一个用Hi地方进行对比

AC代码

#include<cstdio>
#include<iostream>
using namespace std;

int main()
{
    //freopen("in.txt", "r", stdin);
    int n,m;
    while(cin >> n >> m){
        //cin >> n >> m;
        char a[n][m];
        char h[3][3];
        for(int i=0; i<n; i++)
            for(int j=0; j<m; j++)
                cin >> a[i][j];
        
        for(int i=0; i<3; i++)
            for(int j=0; j<3; j++)
                cin >> h[i][j];
        //int flag=0;
        for (int i = 1; i < n-1; i++)
        {
            for (int j = 1; j < m-1; j++)
                if(a[i][j] == h[1][1])     //找到有H的地方,然后比较周围事物
                {
                    int down = (a[i-1][j-1]==h[2][2] && a[i-1][j]==h[2][1] && a[i-1][j+1]==h[2][0] && a[i][j-1]==h[1][2] && a[i][j+1]==h[1][0]
                        && a[i+1][j-1]==h[0][2] && a[i+1][j]==h[0][1] && a[i+1][j+1]==h[0][0]);
                    int up = (a[i-1][j-1]==h[0][0] && a[i-1][j]==h[0][1] && a[i-1][j+1]==h[0][2] && a[i][j-1]==h[1][0] && a[i][j+1]==h[1][2]
                        && a[i+1][j-1]==h[2][0] && a[i+1][j]==h[2][1] && a[i+1][j+1]==h[2][2]);
                    int left = (a[i-1][j-1]==h[2][0] && a[i-1][j]==h[1][0] && a[i-1][j+1]==h[0][0] && a[i][j-1]==h[2][1] && a[i][j+1]==h[0][1]
                        && a[i+1][j-1]==h[2][2] && a[i+1][j]==h[1][2] && a[i+1][j+1]==h[0][2]);
                    int right = (a[i-1][j-1]==h[0][2] && a[i-1][j]==h[1][2] && a[i-1][j+1]==h[2][2] && a[i][j-1]==h[0][1] && a[i][j+1]==h[2][1]
                        && a[i+1][j-1]==h[0][0] && a[i+1][j]==h[1][0] && a[i+1][j+1]==h[2][0]);
                    if(down || up || left || right){
                            //flag = 1;
                            cout << i+1 << " " << j+1 << endl;
                            //break;
                        }
                }
            //if(flag) break;
        }
    }
    return 0;
}
课程设计报告:总体方案设计说明 一、软件开发环境配置 本系统采用C++作为核心编程语言,结合Qt 5.12.7框架进行图形用户界面开发。数据库管理系统选用MySQL,用于存储用户数据与小精灵信息。集成开发环境为Qt Creator,操作系统平台为Windows 10。 二、窗口界面架构设计 系统界面由多个功能模块构成,各模块职责明确,具体如下: 1. 起始界面模块(Widget) 作为应用程序的入口界面,提供初始导航功能。 2. 身份验证模块(Login) 负责处理用户登录与账户注册流程,实现身份认证机制。 3. 游戏主大厅模块(Lobby) 作为用户登录后的核心交互区域,集成各项功能入口。 4. 资源管理模块(BagWidget) 展示用户持有的全部小精灵资产,提供可视化资源管理界面。 5. 精灵详情模块(SpiritInfo) 呈现选定小精灵的完整属性数据与状态信息。 6. 用户名录模块(UserList) 系统内所有注册用户的基本信息列表展示界面。 7. 个人资料模块(UserInfo) 显示当前用户的详细账户资料与历史数据统计。 8. 服务器精灵选择模块(Choose) 对战准备阶段,从服务器可用精灵池中选取参战单位的专用界面。 9. 玩家精灵选择模块(Choose2) 对战准备阶段,从玩家自有精灵库中筛选参战单位的操作界面。 10. 对战演算模块(FightWidget) 实时模拟精灵对战过程,动态呈现战斗动画与状态变化。 11. 对战结算模块(ResultWidget) 对战结束后,系统生成并展示战斗结果报告与数据统计。 各模块通过统一的事件驱动机制实现数据通信与状态同步,确保系统功能的连贯性与数据一致性。界面布局遵循模块化设计原则,采用响应式视觉方案适配不同显示环境。 资源来源于网络分享,仅用于学习交流使用,请勿用于商业,如有侵权请联系我删除!
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值