UVA 10010 - Where's Waldorf? 题解

2023-11-02

Time limit: 3.000 seconds
  Where's Waldorf? 

Given a  m  by  n  grid of letters, (  $1 \leq m,n \leq 20$ ), and a list of words, find the location in the grid at which the word can be found. A word matches a straight, uninterrupted line of letters in the grid. A word can match the letters in the grid regardless of case (i.e. upper and lower case letters are to be treated as the same). The matching can be done in any of the eight directions either horizontally, vertically or diagonally through the grid.

Input 

The input begins with a single positive integer on a line by itself indicating the number of the cases following, each of them as described below. This line is followed by a blank line, and there is also a blank line between two consecutive inputs.

The input begins with a pair of integers, m followed by n$1 \leqm,n \leq 50$ in decimal notation on a single line. The next m lines contain n letters each; this is the grid of letters in which the words of the list must be found. The letters in the grid may be in upper or lower case. Following the grid of letters, another integer k appears on a line by itself ( $1 \leq k \leq 20$). The next k lines of input contain the list of words to search for, one word per line. These words may contain upper and lower case letters only (no spaces, hyphens or other non-alphabetic characters).

Output 

For each test case, the output must follow the description below. The outputs of two consecutive cases will be separated by a blank line.

For each word in the word list, a pair of integers representing the location of the corresponding word in the grid must be output. The integers must be separated by a single space. The first integer is the line in the grid where the first letter of the given word can be found (1 represents the topmost line in the grid, and m represents the bottommost line). The second integer is the column in the grid where the first letter of the given word can be found (1 represents the leftmost column in the grid, and n represents the rightmost column in the grid). If a word can be found more than once in the grid, then the location which is output should correspond to the uppermost occurence of the word (i.e. the occurence which places the first letter of the word closest to the top of the grid). If two or more words are uppermost, the output should correspond to the leftmost of these occurences. All words can be found at least once in the grid.

Sample Input 

1

8 11
abcDEFGhigg
hEbkWalDork
FtyAwaldORm
FtsimrLqsrc
byoArBeDeyv
Klcbqwikomk
strEBGadhrb
yUiqlxcnBjf
4
Waldorf
Bambi
Betty
Dagbert

Sample Output 

2 5
2 3
1 2
7 8
题意,在给你的表中找到于所给单词匹配的单词的首字母的位置。可以往8方向匹配。
因为输出没十分理解, 在两个输出块之间需要一个空行,导致wronganswer多次
#include <iostream>
#include <cstdio>
#include <memory.h>
#include <cmath>
#include <cstdlib>
using namespace std;
#define MAXN 50 + 10

char str[MAXN];
char maze[MAXN][MAXN];
int m,n;
const int mx[] = {+0,-1,-1,-1,+0,+1,+1,+1};
const int my[] = {-1,-1,+0,+1,+1,+1,+0,-1};


bool match(char A,char B){
    int m = A - B;
	if (m == 0 || abs((double)m) == 'a' - 'A')
		return true;
	return false;
}

void mv(int& x,int& y,int i){
	x += mx[i];
	y += my[i];
//	if (x < 0)
//		x += m;
//	if (y < 0)
//		y += n;
//	if (x >= m)
//		x -= m;
//	if (y >= n)
//		y -= n;
}

bool getmatched(int x,int y){
    int l = strlen(str);
	for(int i = 0;i < 8;i++){
		int tempx = x,tempy = y;
		for(int j = 0;j < l;j++){
			if (tempx >= 0 && tempx < m && tempy >= 0 && tempy < n){
				if (match(str[j],maze[tempx][tempy])){
					mv(tempx,tempy,i);
					if (j == l - 1)
						return true;
				}
				else
					break;
			}
			else
				break;
		}
	}
	return false;
}



int main(){
    //freopen("in.txt","r",stdin);
	int T;
	int cs = 0;
	for(scanf("%d",&T);T;T--){
	    if (cs)
	    printf("\n");
		scanf("%d%d",&m,&n);
		for(int i = 0;i < m;i++){
			scanf("%s",maze[i]);
		}
		int t;
		for(scanf("%d",&t);t;t--){
			int flag = 0;
			scanf("%s",str);
			for(int i = 0;i < m && !flag;i++){
				for(int j = 0;j < n && !flag;j++){
					if (match(maze[i][j],str[0])){
						if (getmatched(i,j)){
							flag = 1;
							cout<<i+1<<" "<<j+1<<endl;
						}
					}
				}
			}
		}
		//output a blank line
		if (cs == 0) cs = 1;
	}
	return 0;
}


本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

UVA 10010 - Where's Waldorf? 题解 的相关文章

  • [极客大挑战 2019]Http(BUUCTF)

    前言 这篇文章还是是为了帮助一些 像我这样的菜鸟 找到简单的题解 题目描述 解题工具 我用fiddler抓包 burpsuite也可以 解题过程 用F12查看一下源代码 发现Secret php 进入是一个高档页面 翻译一下意思是 来源不是
  • UVA-1354 天平难题 题解答案代码 算法竞赛入门经典第二版

    GitHub jzplp aoapc UVA Answer 算法竞赛入门经典 例题和习题答案 刘汝佳 第二版 这道题需要 1 遍历二叉树的每种构成方式 我这里每次把当前所有结点列出 然后遍历选取两个组合构成一个新结点 原来的结点剔除 新结点
  • HDU - 2100 Lovekey

    XYZ 26进制数是一个每位都是大写字母的数字 A B C X Y Z 分别依次代表一个0 25 的数字 一个 n 位的26进制数转化成是10进制的规则如下 A0A1A2A3 An 1 的每一位代表的数字为a0a1a2a3 an 1 则该X
  • 【CLYZ集训】马可波罗【按位】【博弈论】

    题目大意 有两个人 n n n堆石子 每个人轮流取 每次可以取1 x x x个 最后没得取的人输 两人都采取最优策略 问对于 x
  • UVa 120 Stacks of Flapjacks

    Background Stacks and Queues are often considered the bread and butter of data structures and find use in architecture p
  • 【NOI2018模拟3.26】Cti

    Description 有一个 n m 的地图 地图上的每一个位置可以是空地 炮塔或是敌人 你需要操纵炮塔消灭敌人 对于每个炮塔都有一个它可以瞄准的方向 你需要在它的瞄准方向上确定一个它的攻击位置 当然也可以不进行攻击 一旦一个位置被攻击
  • LeetCode—200.岛屿数量(Number of Islands)——分析及代码(C++)

    LeetCode 200 岛屿数量 Number of Islands 分析及代码 C 一 题目 二 分析及代码 1 深度优先搜索 1 思路 2 代码 3 结果 三 其他 一 题目 给定一个由 1 陆地 和 0 水 组成的的二维网格 计算岛
  • 基于一道ctf 引发的 TP链分析

    回看 newstarctf week 3 的web题 想了想看看tp链吧 这道题是tp5 1 的版本 链比5 0的 短而且清晰 基于我这个shaluan tp不知道为什么动态调试出了问题 就只能静态分析了 首先是定入口 这里5 0和5 1的
  • HDU 1106 排序

    题目 输入一行数字 如果我们把这行数字中的 5 都看成空格 那么就得到一行用空格分割的若干非负整数 可能有些整数以 0 开头 这些头部的 0 应该被忽略掉 除非这个整数就是由若干个 0 组成的 这时这个整数就是0 你的任务是 对这些分割得到
  • UVa10881题解报告

    题目 L长的棍子上有n个蚂蚁 他们分别向左或右爬 速度为1 求T时间后各蚂蚁的状态 题解 白书给出了一个很巧妙的解法 将蚂蚁看作质点 相撞掉头等于对穿而过 因为掉头所以 他们最后的顺序与输入时在棍子上的顺序相同 所以只要记录下初始状态下蚂蚁
  • HDU - 1020 Encoding

    Given a string containing only A Z we could encode it using the following method Each sub string containing k same chara
  • 【全网最细PAT题解】【PAT乙】1044 火星数字(测试点2,测试点4详细解释)

    题目链接 1044 火星数字 题目描述 火星人是以 13 进制计数的 地球人的 0 被火星人称为 tret 地球人数字 1 到 12 的火星文分别为 jan feb mar apr may jun jly aug sep oct nov d
  • CF1512C A-B Palindrome 题解

    题目大意 给定一个字符串 长度为 a b a b a b 给定 a a a
  • 2011年北京大学计算机研究生机试真题(题解)

    九度OJ题目传送门 2011年北京大学计算机研究生机试真题 鸡兔同笼 题目描述 一个笼子里面关了鸡和兔子 鸡有2只脚 兔子有4只脚 没有例外 已经知道了笼子里面脚的总数a 问笼子里面至少有多少只动物 至多有多少只动物 输入 第1行是测试数据
  • 2020年团体程序设计天梯赛-总决赛 L2-2 口罩发放

    L2 2 口罩发放 25分 输入格式 输出格式 输入样例 输出样例 样例解释 题解 L2 2 口罩发放 25分 为了抗击来势汹汹的 COVID19 新型冠状病毒 全国各地均启动了各项措施控制疫情发展 其中一个重要的环节是口罩的发放 某市出于
  • POJ 3259 Wormholes(最短路——Bellman-ford)

    A Wormholes While exploring his many farms Farmer John has discovered a number of amazing wormholes A wormhole is very p
  • 2022第十三届蓝桥杯国赛真题javaB组

    文章目录 试题A 重合次数 试题B 数数 试题C 左移右移 试题D 窗口 试题E 迷宫 试题F 小球称重 试题G 背包与魔法 试题H 修路 试题I 围栏 试题J 好数之和 试题A 重合次数 本题总分 5 分 问题描述 在同一天中 从上午6
  • UVa 12504 Updating a Dictionary

    Problem uva onlinejudge org index php option com onlinejudge Itemid 8 page show problem problem 3948 题意 貌似是模拟 Source Cod
  • 《数据结构与算法》期末考试

    数据结构与算法 期末考试 判断题 单选题 填空题 函数题 主观题 判断题 已知一棵二叉树的先序遍历结果是ABC 则CAB不可能是中序遍历结果 T 所谓 循环队列 是指用单向循环链表或者循环数组表示的队列 F 只有当局部最优跟全局最优解一致的
  • LeetCode题解—260.只出现一次的数字Ⅲ

    题目地址 260 只出现一次的数字 III 力扣 LeetCode 题解 这道题是基于寻找只出现一次的数字 上的拓展 136 只出现一次的数字 力扣 LeetCode 在 中 我们只需要把所有的数字异或一遍即可 因为只有一个数字是唯一的 但

随机推荐

  • Java学习总结-IO流的概念理解

    一 Java io流 的概念 流存在的意义 1 数据的传输量很大 2 内存有限 3 带宽有限 而Stream可以1点1点地逐步传输所有数据 这就是Stream存在的根本意义 想想我们是怎样下载1个大文件的 下载软件 例如x雷 并不会占用你内
  • IOS推送总结

    此文主要以证书生成配置为主 实现简单推送 部分截图与内容来自于互联网 若对大家有所帮助 还请给个赞O O 如有误 请指出 一起探讨 一 推送原理 Provider是指某个iPhone软件的Push服务器 APNS 是Apple Push N
  • Java中instanceof关键字的理解

    java 中的instanceof 运算符是用来在运行时指出对象是否是特定类的一个实例 instanceof通过返回一个布尔值来指出 这个对象是否是这个特定类或者是它的子类的一个实例 用法 result object instanceof
  • linux宝塔命令

    安装宝塔 Centos安装脚本 yum install y wget wget O install sh http download bt cn install install sh sh install sh Ubuntu Deepin安
  • Linux中的Chrony时间同步服务

    目录 一 时间同步 1 概念 2 时间同步在运维工作中的作用 3 时间同步完成方法 1 NTP时间服务 centos 6 2 Chrony时间服务 二 Chrony时间服务 1 Chrony介绍 2 Chrony的优点 三 Chrony安装
  • shell脚本中grep时关于变量带双引号的小问题

    今天在写一个shell脚本的时候 有一个操作是使用grep命令在一个文件中搜索指定内容 指定内容存放在文件中 使用一个变量去获取文件中内容 再传到grep命令中去 这段代码如下 for target in cat content txt d
  • java游戏服务器开发需要学习的技术

    一 游戏服务器编程语言的选择 所谓的游戏服务器编程语言其实有很多 基本上任何一种语言都可以作为游戏服务器的编程语言 这需要根据自己游戏的类型和要求加以选择 比如C Java Erlang go等等 目前我用过的只有C 和Java 但是以Ja
  • 查看broker节点信息

    kafka查看broker节点信息可以进入zookeeper客户端中查看 运行zkCli sh进入客户端 输入ls 可以看到相关的节点 输入 ls broker ids 可以看到broker数
  • Hyperledger Fabric网络快速启动

    目录 1 网络服务配置 2 关联的docker compose base yaml 各Peer节点容器设置如下信息 3 被关联的Peer base yaml 4 启动网络 2 完成通道的创建 2 1将节点加入应用通道 更新锚节点 2 为什么
  • 第九章:C语言数据结构与算法初阶之堆

    系列文章目录 文章目录 系列文章目录 前言 一 堆的定义 二 堆的实现 三 堆的接口函数 1 初始化 2 销毁 3 插入 4 删除 5 判空 6 元素个数 四 堆应用的原理 五 堆排序 1 建堆 2 排序 六 堆的应用 TOPK 1 什么是
  • [Excel VBA]状态栏如何显示文字 ?

    本文译至 http itpro nikkeibp co jp atcl column 15 090100207 090100148 Application StatusBar 字符串 画面最下方的状态栏可以显示任意的字符串 显示的字符串可以
  • 生产数据实时同步到预生产

    生产数据库同步到预生产 实现实时同步 参见 MySQL binlog2sql 非主从实时同步 恢复误删数据 同步昨晚的备份 基于昨晚的全备 在预生产服务器添加定时执行此脚本 重置数据库 刷入昨晚的全备 0 4 bin sh scripts
  • 基于舒适性的速度规划。对路面进行分级,基于路面状况对舒适性的影响对速度进行规划

    基于舒适性的速度规划 对路面进行分级 基于路面状况对舒适性的影响对速度进行规划 建模仿真MATLAB Simulink编号 54150653898883414Hsvssvg
  • makefile找不到

    如果下载的代码执行make j时找不到makefile 需要自己生成 现在有makefile am sudo apt install automake libtool m4 autoconf autoconf autoreconf vif
  • 【random库与math库】python程序对一组随机数求平均值,标准差,中位数,离差,离差方,总体方差,样本方差,样本标准差

    基本统计值计算 使用random库生成随机数100个 1 100 的整数 同时借用math库进行了简单的计算 对生成的一组随机数求平均值 标准差 中位数 离差 离差方 总体方差 样本方差 样本标准差 计算公式如下 程序代码如下 from m
  • 单片机开发板sv32wb0x,C语言,创建websocket客户端

    本人参考大佬的代码移植进单片机 调试BUG后并且成功跑通 如果你不了解websocket协议建议参考Linux下c语言实验Websocket通讯 含客户端和服务器测试代码 我只是把这位大佬写的提取出我需要的 基于单片机lwip网络编程 本代
  • Docker私有镜像仓库harbor搭建

    Harbor搭建镜像仓库 文章目录 Harbor搭建镜像仓库 Harbor简述 系统环境与软件版本说明 安装docker 安装docker compose 安装Harbor 使用Harbor上传下载镜像基于http https协议 访问页面
  • GitHub:[亲测方法简单+有效] 成功解决 Failed to connect to github.com port 443: Timed out

    01 遇到的问题 使用以下命令 提交代码到远程仓库时 git push u origin master 遇到如下问题 fatal unable to access https github com xxx Failed to connect
  • angular2 表单拆成多个组件及提交验证问题

    angular2表单最常用的方法就是在input或者textarea里直接添加formControlName或者formGroupName进行数据双向绑定并验证 1
  • UVA 10010 - Where's Waldorf? 题解

    Time limit 3 000 seconds Where s Waldorf Given a m by n grid of letters and a list of words find the location in the gri