下周开始就省选了,ACM的日子在今年内应该就会结束了,大三了,最后一次机会了,小小感伤一下……

今天广州下大雨,心情怪怪的,感觉码不出质量高的,又很久没做过PC了,就刷刷水题吧。

老实说Program challenge的题目,输入输出特麻烦……搞到我PE了三次,从没试过……我今天的转速很低。

这题目有点像字符串匹配,规模也很小,随便写了一下。

我发现我现在做字符串很喜欢用map。c++有三宝,stl,template,class.其中我觉得最重要的就前两者啦,虽然很多用都以面向对象来形容c++,但是c++的更精华在与stl,模版。

好啦,回归正题,

题目要求按米字八个方向寻找单词,并是上左优先,一定能找到。

我的算法(准确来说是做法,没什么算法可言)。经过基本的tolow操作,化成小写字母,之后利用map,对每个出现的字母映射到一个vector,从上到下,从左到右的位置。

之后对每一个要匹配的单词,取出第一个字母,找到对应的vector,每一个point去做检索,检索到了,就是最优了,输出,OK。

由于今天心情真的不怎么样,做完SOLVED后没有看别人代码了。

/*******************************************************************************/
/* OS : 3.2.0-58-generic #88-Ubuntu SMP Tue Dec 3 UTC 2013 GNU/Linux
* Compiler : g++ (GCC) 4.6.3 (Ubuntu/Linaro 4.6.3-1ubuntu5)
* Encoding : UTF8
* Date : 2014-03-30
* All Rights Reserved by yaolong.
*****************************************************************************/
/* Description: ***************************************************************
*****************************************************************************/
/* Analysis: ******************************************************************
*****************************************************************************/
/*****************************************************************************/ #include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<vector>
#include<map>
using namespace std;
class point
{
public:
int x,y;
point(int x,int y)
{
this->x=x;
this->y=y;
}
point() {} };
char toLow(char a)
{
if(a<'a') return a+'a'-'A';
return a; }
map<char,vector<point> > mp;
vector<string> str;
char p[60][60];
int dx[]= {1,1, 1,-1,-1,-1,0, 0};
int dy[]= {1,0,-1, 1, 0,-1,1,-1};
void fun(string s)
{
int siz=s.size();
int i=0,j;
char cur_s;
int cur_i=1;
point pt=mp[s[0]][i];
while(cur_i<siz)
{
pt=mp[s[0]][i++]; for(j=0; j<8; j++)
{
int nx=pt.x,ny=pt.y;
int flag=1;
cur_i=1; while(cur_i<siz)
{ cur_s=s[cur_i];
nx+=dx[j];
ny+=dy[j];
if(p[nx][ny]!=cur_s)
{
flag=0;
break;
} cur_i++; }
if(flag) break; } }
cout<<pt.x<<" "<<pt.y<<endl; }
int main()
{ char tmp;
int cases,n,m,i,j,k;
int first=1; cin>>cases; while(cases--)
{
if(first) first=0;
else cout<<endl;
mp.clear();
str.clear();
getchar();
cin >>n>>m;
memset(p,'.',sizeof(p));
for(i=1; i<=n; i++)
for(j=1; j<=m; j++)
{
cin>>tmp;
tmp=toLow(tmp);
mp[tmp].push_back(point(i,j));
p[i][j]=tmp; }
cin>>k;
str.resize(k);
for(i=0; i<k; i++)
{
cin>>str[i];
for(j=0; j<str[i].length(); j++)
str[i][j]=toLow(str[i][j]);
}
for(i=0; i<k; i++)
{ fun(str[i]); } } return 0; }

PC110302/UVA10010的更多相关文章

  1. UVA大模拟代码(白书训练计划1)UVA 401,10010,10361,537,409,10878,10815,644,10115,424,10106,465,10494

    白书一:http://acm.hust.edu.cn/vjudge/contest/view.action?cid=64609#overview 注意UVA没有PE之类的,如果PE了显示WA. UVA ...

随机推荐

  1. Python的高级特性之切片、迭代、列表生成式、生成器

    切片 切片就是获取一个list.tuple.字符串等的部分元素 l = range(100) #取[0,5)元素 print(l[:5]) #[0, 1, 2, 3, 4] #在[0,99]中每隔10 ...

  2. 让IE6兼容position:fixed

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...

  3. BAT-使用BAT方法判断网络启动EXE(快捷方式)

      原理思路:先启动iNode,如果访问www.baidu.com成功,证明网通了,这时就启动GXT和邮件等.PS:因为对BAT不清楚,所以自己写的东东可能有问题,希望大家有了解BAT的,看一下是否正 ...

  4. spring boot 实践

    二.实践 一些说明: 项目IDE采用Intellij(主要原因在于Intellij颜值完爆Eclipse,谁叫这是一个看脸的时代) 工程依赖管理采用个人比较熟悉的Maven(事实上SpringBoot ...

  5. 了解node.js

    转载自http://debuggable.com/posts/understanding-node-js:4bd98440-45e4-4a9a-8ef7-0f7ecbdd56cb 当我向人们介绍nod ...

  6. [D3] 8. Margins

    If you want ot add margins, should append graphics container in svg var svg = d3.select('#chartArea' ...

  7. mybatis09

    1mybatis开发dao的方法 .1SqlSession作用范围 是使用局部变量.成员变量,还是形参? 1.1.1SqlSessionFactoryBuilder SqlSessionFactory ...

  8. Linux下设置最大文件打开数nofile及nr_open、file-max

    在开发运维的时候我们常常会遇到类似“Socket/File: Can’t open so many files”,“无法打开更多进程”,或是coredump过大等问题,这些都可以设置资源限制来解决.今 ...

  9. hadoop错误Ignoring exception during close for org.apache.hadoop.mapred.MapTask$NewOutputCollector@17bda0f2 java.io.IOException Spill failed

    1.错误    Ignoring exception during close for org.apache.hadoop.mapred.MapTask$NewOutputCollector@17bd ...

  10. xcode 4 安装cocos2d-x 2.1.4

    http://blog.csdn.net/xiaominghimi/article/details/6937685 从今天开始Himi将陆续更新cocos2d-X的博文,毕竟cocos2d-X的跨平台 ...