下周开始就省选了,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. [CODEVS2055]集合划分

    对于从1到N(1<=N<=3)的连续整数集合,划分成两个子集合,使得每个集合的数字之和相等.举个例子,如果N=3,对于{1,2,3}能划分成两个子集合,他们每个的所有数字和是相等的:{3} ...

  2. How Do I Deploy a Windows 8 App to Another Device for Testing?

    If your developing a new Windows 8 app and you want to test it on another device (e.g. Surface), you ...

  3. 零基础学习视频解码之FFMpeg中比较重要的函数以及数据结构

    http://www.cnblogs.com/tanlon/p/3879081.html 在正式开始解码练习前先了解下关于FFmpeg中比较重要的函数以及数据结构. 1. 数据结构:  (1) AVF ...

  4. 怎样在Yii中显示静态页

    在web应用中,我们经产更需要显示静态页,如“关于我们”等,这些文件通常是静态页,通常有如下几种处理方法: 1.把独立的html文件存在Web服务器能直接访问的目录下.这种方案的缺点是很难维护网页布局 ...

  5. c#复制图片到粘贴板

    string fielN; private void button1_Click(object sender, EventArgs e) { OpenFileDialog saveFileDialog ...

  6. Yii2 ActiveForm表单自定义样式

    实例: <?php $form = ActiveForm::begin([ 'fieldConfig' => [ 'template' => '<div class=" ...

  7. Thoughtworks的技术雷达

    博客搬到了fresky.github.io - Dawei XU,请各位看官挪步.最新的一篇是:Thoughtworks的技术雷达.

  8. [TypeScript] Using Exclude and RootDir until File Globs Lands in 2.0.

    Files globs will be available in TypeScript 2.0, so in the meantime, we need to use "exclude&qu ...

  9. trace openjdk from systemtap

    here are several different tactics to trace openjdk from systemtap. The first relies on sys/sdt.h dt ...

  10. Yet Another 10 Common Mistakes Java Developers Make When Writing SQL (You Won’t BELIEVE the Last One)--reference

    (Sorry for that click-bait heading. Couldn’t resist ;-) ) We’re on a mission. To teach you SQL. But ...