UVA 10010 - Where's Waldorf?(字符串)

保姆级教程:在Windows 11上用Anaconda搞定Wave2Lip环境(避坑libsndfile.so错误) 本文提供在Windows 11上使用Anaconda配置Wave2Lip环境的完整指南,涵盖从Python 3.6环境搭建到视频生成实战的全过程。特别针对Windows平台特有的libsndfile.so错误提供解决方案,并分享与GFP-GAN联合作业的画质增强技巧,帮助用户高效实现AI唇语同步。 阅读详情

  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



Miguel Revilla 
2000-08-22


================================

题目就是在一个表里找单词,输出第一个字母的位置


循环找到第一个字母的位置,分别向八个方向找单词(注意边界范围),找到了返回1,并记录下当前位置


#include <iostream>
#include <cstdio>
#include <cstring>

using namespace std;

int dx[8]={-1,-1,-1,0,0,1,1,1};
int dy[8]={-1,0,1,-1,1,-1,0,1};
char s[55][55],word[60];
int n,m,len;

int search(char str[],int x,int y,int dx,int dy)
{
    int newx=x;
    int newy=y;
    int l=0;
    while(newx>=0&&newy>=0&&newx<n&&newy<m)
    {
        if(str[l++]!=s[newx][newy])
            break;
        if(l==len)
        {
            //cout<<str[l-1]<<endl;
            return 1;
        }
        newx+=dx;
        newy+=dy;
    }
    return 0;
}

int main()
{
    int t,tt,x,y;
    scanf("%d",&t);
    while(t--)
    {
        scanf("%d%d",&n,&m);
        for(int i=0;i<n;i++)
        {
            scanf("%s",s[i]);
            for(int j=0;j<m;j++)
            {
                if(s[i][j]>='A'&&s[i][j]<='Z')
                    s[i][j]+=32;
            }
        }
        scanf("%d",&tt);
        while(tt--)
        {
            memset(word,0,sizeof(word));
            scanf("%s",word);
            len=strlen(word);
            for(int i=0;i<len;i++)
            {
                if(word[i]>='A'&&word[i]<='Z')
                    word[i]+=32;
            }
            int flag=0;
            for(int i=0;i<n;i++)
            {
                for(int j=0;j<m;j++)
                {
                    for(int k=0;k<8;k++)
                    {
                        if(search(word,i,j,dx[k],dy[k]))
                        {
                            flag=1;
                            x=i;
                            y=j;
                            break;
                        }
                    }
                    if(flag) break;
                }
                if(flag) break;
            }
            printf("%d %d\n",x+1,y+1);
        }
        if(t) cout<<endl;
    }
    return 0;
}



【DMA】认识 DMA 及其工作流程(与传统CPU存取方式的区别) 阅读详情

相关推荐

DDR3性能优化实战:如何用Xilinx MIG控制器实现800MHz稳定读写(7系列FPGA版)

本文深入探讨了在Xilinx 7系列FPGA上使用MIG控制器实现DDR3存储器800MHz稳定高速读写的实战优化技巧。文章聚焦于高级时序调优、Bank Machine调度策略、用户接口设计优化以及利用ILA进行信号完整性调试,旨在帮助工程师突破性能瓶颈,实现接近理论峰值的稳定带宽,并为进一步冲刺更高频率提供进阶调参指南。

seed的博客 776

Where's Waldorf?

开始没看清楚题意,把题看复杂了,于是使用了递归,写完后一看发现自己写的不就是以前自己没看懂的深度优先搜索(DFS)么?后来发现还真是,自己居然“发明”了DFS,而且用的还是递归栈,不禁得意,结果多次WA,不知为何。无奈之下只好拿别人的代码对拍,把样例数据加了点,发现自己的程序得出

laciqs 1458

WPF实战:利用Live Charts实现高性能动态曲线可视化

本文详细介绍了如何在WPF中使用Live Charts实现高性能动态曲线可视化,特别适用于工业监控和金融分析等实时数据场景。通过增量渲染、内存复用和硬件加速等核心技术,Live Charts能够高效处理高频数据更新,显著提升图表流畅度。文章提供了从基础实现到工业级优化的完整解决方案,帮助开发者应对各种性能挑战。

weixin_29189373的博客 407

[ACM] Where's Waldorf?

Background Given an m by n grid of letters 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. ...

tudusi 254

DIY音乐播放器:用VS1053模块+Arduino打造你的专属MP3播放器(附完整代码)

本文详细介绍了如何使用VS1053音频解码模块与Arduino开发板,从零开始构建一个功能完备的桌面级MP3播放器。内容涵盖硬件架构设计、SPI总线共享、底层驱动编写、双缓冲区数据流管理以及用户交互实现,并提供完整的代码示例与性能优化建议,帮助创客打造高度可定制的专属音乐播放设备。

weixin_29189003的博客 287

别再为域名备案发愁了!微信小程序后端调用,试试这个‘官方捷径’——云托管

本文介绍了微信小程序后端部署的新思路——利用微信云托管服务绕过域名备案难题。通过详细的环境准备、数据库配置、服务部署和小程序端调用方案,帮助开发者快速实现小程序与后端服务的无缝对接,大幅缩短上线周期并降低运维成本。

weixin_29243279的博客 676

Where's Waldorf? -uva手记

昨天晚上无限太烂没刷的起来,这水题我早上爬起来花了大概一个半小时才AC下了,不是这题多么难,是这题数据给的太坑爹外加英语各种看不懂,翻译先自己翻译了半个小时,这尼玛。。之后就是题目给的测试数据,给了一组!!!就是这一组我没看出来他的数据间的空行,还有最后一行的控制,这也是坑,不过刷过了“三角波”那道关于练习空格的“坑爹战斗机”的题以后,这个坑也不算深 先说错误,8个方向一开始漏了2个,之后是不知

花月阁 767

AI智能体实战:从LangChain到多智能体协作的自动化新范式

在人工智能技术快速发展的今天,大语言模型(LLM)已成为推动自动化变革的核心驱动力。其原理在于通过深度学习海量文本数据,使模型能够理解、生成自然语言并执行推理任务。这一技术进步催生了AI智能体(AI Agent)这一新兴概念,它赋予自动化系统自主决策和动态规划能力,从而突破了传统脚本和RPA工具在固定流程上的局限。从技术价值看,AI智能体框架通过封装LLM调用、工具集成与流程编排,显著降低了构建复杂人机协同应用的开发门槛。在实际应用场景中,智能体尤其擅长处理信息调研、内容创作辅助、数据分析等需要处理非结构化

weixin_33730836的博客 773

UVA 10010- Where's Waldorf?(八方向寻找字符串)

Where's Waldorf? Time Limit:3000MS     Memory Limit:0KB     64bit IO Format:%lld & %llu Submit Status Description   Where's Waldorf?  Given a m by n grid of lett

Rocky0429 1773

如何给数据添加高斯白噪声?

首先测试集应该是加噪声的,至于训练集需不需要加噪声就见仁见智了。我个人测试的结果是,训练集如果不加噪声的话效果特别差,如果加噪声的话效果就比较好接受,大家可以自己试试看。在轴承故障研究中免不了要涉及到给数据主动加入噪声的情况,一般我们加的是高斯白噪声。由于热噪声是由大量自由电子的运动产生的,其统计特性服从高斯分布,故常将热噪声称为高斯白噪声。的频谱是均匀分布的,好像白光的频谱在可见光的频谱范围内均匀分布那样,所以热噪声又常称为。定义一:如果一个噪声,它的瞬时值服从。又是均匀分布的,则称它为高斯白噪声。

weixin_50642818的博客 5220

Allan方差这个工具,怎么把它用的更顺手?(附Allan方差、动态Allan方差代码)

本文详细说明了Allan方差和动态Allan方差的计算过程,并通过递归运算和时间序列选择两种算法提高动态Allan方差的计算效率。文末提供了快速动态Allan方差计算代码。

victoryqian528的博客 374

uva 10010 Where's Waldorf?(DFS字符串查找)

Where's Waldorf?  Given a m by n grid of letters, ( ), 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 o

不慌不忙、不急不躁 1451

假人有限元模型

假人模型,车辆碰撞假人有限元模型,适合做乘员安全的研究者利用

UVa10010_Where's Waldorf?(小白书字符串专题)

Description   Where's Waldorf?  Given a m by n grid of letters, ( ), and a list of words, find the location in the grid at which the word can be found. A word matches a str

_nplus 908

ET2012新版免狗免安装绿色软件

ET2012新版免狗免安祖昂绿色软件。,新界面,新视觉,

lwip-2.0.3

lwip是瑞典计算机科学院(SICS)的Adam Dunkels 开发的一个小型开源的TCP/IP协议栈。实现的重点是在保持TCP协议主要功能的基础上减少对RAM 的占用。

uva 10010 Where's Waldorf?(字符串处理)

题意很明确,给一个字符网格,求匹配的数字

渐近自由 520

NTscan扫描工具

ntscan是一个扫描器,可以扫描没有密码和弱密码的共享,先到配置文件中填写猜测的用户名和密码,扫描过程中右侧出现的是扫描日志。

UVa 10010 - Where's Waldorf?

/* coder: ACboy date: 2010-2-24 result: AC description: UVa 10010 - Wheres Waldorf? lesson: see the problem clear. 1 <= m, n <= 50; at first I consider the max of the m and n is 25.*/

个人独立博客http://www.acb0y.cn/ 1530

UVA 题目10010 - Where's Waldorf?

Where's Waldorf?  Given a m by n grid of letters, ( ), 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 o

落日小屋 3793

UVA 10010 Where's Waldorf?

Given a m by n grid of letters, (1  m; n  50), and a list of words, nd the location in the grid at which the word can be found. A word matches a straight, uninterrupted line of letters in the grid

哈希的博客 374

UVA - 10010 Where's Waldorf?

UVA - 10010 Where’s Waldorf?写的很繁琐,代码很冗长。题目大意:给一段字符串,作用类似棋盘,在这段字符串中找出给定字段最近的位置。解题思路:暴力求,八个方向全写。先查首字母,找到相同的就查第二个字母在八个方向的哪个方向能对应,以此类推。注意点:一开始没有考虑到所查找的字段只有一个字符的情况,这样,第二个字母就是’\0’,那么原先判断第二个字母是否相等时,只会找棋盘边界的位置

Together with keyboard (ノ`Д´)ノ 249

UVA 10010 Where's Waldorf?

StatisticLOGOUTwikioi_bai UVA - 10010 Where's Waldorf? Time Limit: 3000MS   Memory Limit: Unknown   64bit IO Format: %lld & %llu Submit Status Description

自己选择的路,就算跪着也要走完。 683

UVA 10010 Where's Waldorf?

题目大意:给定一个矩阵,里面是一些字母。要求找到指定字符串的位置,其中单词必须是一条直线(刚开始这里没看到 = =,英语是硬伤。)所以可以直接往八个方向搜索,不过这里只是往一个方向搜索(满足直线要求)。由于不区分大小写,搜索之前可以做个预处理,将小写字母全部转化成大写字母。 #include #include #include #include using namespace std;

hahahaha 951

UVa10010 - Where's Waldorf?-字符串(8方向搜索)-难度3

题目链接:http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=951   Where's Waldorf?  Given a m by n grid of letters, ( ), and a l

Ieyasu的专栏 683

UVA10010 Where's Waldorf?【水题】

Given a m by n grid of letters, (1 ≤ m, n ≤ 50), 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 g...

海岛Blog 529

UVA 10010 Where's Waldorf?

Where's Waldorf?  Given a m by n grid of letters, ( ), 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 o

Clearlemon 568

UVa Problem Solution: 10010 - Where's Waldorf

I use the naive string search method that scans for the eight directions at each point in the matrix. Due to the relatively small input size, this method work well enough to get the top 20% ranking.Co

Kaipeng Liu's Column 2386

UVa Problem 10010 Where’s Waldorf?(寻找单词)

// Where’s Waldorf? (序找单词) // PC/UVa IDs: 110302/10010, Popularity: B, Success rate: average Level: 2 // Verdict: Accepted // Submission Dat

寂静山林 2659
上一篇: UVA 401 - Palindromes(字符串)
下一篇: UVA 10361 - Automatic Poetry(字符串)
coco430
博客等级 码龄14年 9粉丝 107原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值