http://www.bnuoj.com/bnuoj/contest_show.php?cid=2876#problem/31796

【题意】:

  如题,注意大小写情况

【code】:

 #include <iostream>
#include <stdio.h>
#include <string.h>
#include <ctype.h>
#include <algorithm>
#include <queue> using namespace std; struct Nod
{
int x,y,step;
}nd1,nd2; int step[][];
char temp[];
int cx[]={,-,,,,-}; //定义六个方向可以移动
int cy[]={,,-,,-,};
char str[][]={
"`1234567890-=***",
"*QWERTYUIOP[]\\**", //这里的反斜杠‘\’必须打两个进行转义
"*ASDFGHJKL;'****",
"*ZXCVBNM,./*****",
"*** ********",
}; int mark[][]; void BFS(int x,int y,int nx,int ny) //4 14 / 5 14
{
memset(mark,,sizeof(mark));
nd1.x = x;
nd1.y = y;
nd1.step = ;
char ch = str[x][y];
step[ch][ch] = ;
if(temp[ch]!=)
{
step[temp[ch]][temp[ch]]=;
step[ch][temp[ch]]=;
step[temp[ch]][ch]=;
}
mark[x][y]=;
queue<Nod> Q;
Q.push(nd1);
while(!Q.empty())
{
nd2 = Q.front();
Q.pop();
int i;
for(i=;i<;i++)
{
nd1.x = nd2.x + cx[i];
nd1.y = nd2.y + cy[i];
nd1.step = nd2.step + ;
if(nd1.x>=&&nd1.x<nx&&nd1.y>=&&nd1.y<ny&&str[nd1.x][nd1.y]!='*'&&!mark[nd1.x][nd1.y])
{
mark[nd1.x][nd1.y]=;
step[str[nd1.x][nd1.y]][ch]=nd1.step;
if(temp[str[nd1.x][nd1.y]]!=)
{
step[temp[str[nd1.x][nd1.y]]][ch]=nd1.step;
}
if(temp[ch]!=)
{
step[str[nd1.x][nd1.y]][temp[ch]]=nd1.step;
}
if(temp[str[nd1.x][nd1.y]]!=&&temp[ch]!=)
{
step[temp[str[nd1.x][nd1.y]]][temp[ch]]=nd1.step;
}
Q.push(nd1);
}
}
}
} void getStepArr()
{
memset(step,-,sizeof(step));
char cc[]="CVBNM,";
int i,j,k;
for(i=;i<;i++)
{
for(j=;j<;j++)
{
char ch = str[i][j];
if(ch!='*')
{
BFS(i,j,,);
}
}
}
//对空格键单独处理
for(i=;i<;i++)
{
for(j=;j<;j++)
{
char ch = str[i][j];
if(ch!='*')
{
int mins = ;
for(k=;k<;k++)
{
if(mins>step[ch][cc[k]])
{
mins=step[ch][cc[k]];
}
}
step[ch][' ']=mins+;
step[' '][ch]=mins+;
if(temp[ch]!=)
{
step[temp[ch]][' ']=mins+;
step[' '][temp[ch]]=mins+; }
}
}
}
} char quer[]; int main()
{
memset(temp,,sizeof(temp));
temp['`']='~';
temp['']='!';
temp['']='@';
temp['']='#';
temp['']='$';
temp['']='%';
temp['']='^';
temp['']='&';
temp['']='*';
temp['']='(';
temp['']=')';
temp['-']='_';
temp['=']='+';
temp['[']='{';
temp[']']='}';
temp['\\']='|';
temp[';']=':';
temp['\'']='"';
temp[',']='<';
temp['.']='>';
temp['/']='?';
getStepArr();
while(gets(quer))
{
int len = strlen(quer);
int i,ans=;
for(i=;i<len;i++) quer[i]=toupper(quer[i]);
for(i=;i<len-;i++)
{
ans+=step[quer[i]][quer[i+]];
}
printf("%d\n",ans);
}
return ;
}

bnuoj 31796 键盘上的蚂蚁(搜索模拟)的更多相关文章

  1. form表单提交和ajax表单提交,关于移动端如何通过软键盘上的【搜索】和【前进】进行提交操作

    [文章来源]由于自己对于form研究甚少,所以一直用的都是AJAX进行提交,这次后台提出要用form提交,顺便深入研究一下:之前在做表单的时候,发现input可以通过设置不同的type属性,调用不同的 ...

  2. js 移动端写搜索时怎么调用软键盘上面的搜索按钮

    这段时间一直在做移动端,所以遇到很多问题,现在很多网站在做移动端搜索的时候都不会在后面加一个搜索按钮,而是直接调用输入法上面的搜索搜索按钮进行搜索 input的一个新属性给我们提供非常方便的书写, 就 ...

  3. BZOJ1033:[ZJOI2008]杀蚂蚁antbuster(模拟)

    Description 最近,佳佳迷上了一款好玩的小游戏:antbuster.游戏规则非常简单:在一张地图上,左上角是蚂蚁窝,右 下角是蛋糕,蚂蚁会源源不断地从窝里爬出来,试图把蛋糕搬回蚂蚁窝.而你的 ...

  4. 【NOIP 2011】Mayan游戏(搜索+模拟)

    描述 Mayan puzzle是最近流行起来的一个游戏.游戏界面是一个7行5列的棋盘,上面堆放着一些方块,方块不能悬空堆放,即方块必须放在最下面一行,或者放在其他方块之上.**游戏通关是指在规定的步数 ...

  5. 如何使用alt键+数字键盘上的数字键打出特殊符号

    如何使用alt键+数字键盘上的数字键打出特殊符号 有时当我需要画示意图说明一个问题,但是苦于没有合适的符号,因此,这篇博文将简单介绍一些特殊的符号方便自己以及大家使用. 实现原理很简单:所有的字符(包 ...

  6. 如何用Jquery判断在键盘上敲的哪个按键

    有时候我们需要判断我们在键盘上敲了哪个键,这个需要查询下键盘上的键对应的值是多少,比如Enter键是13. 下面是Jquery代码,别忘了引用Jquery包哈. <script type=&qu ...

  7. IQKeyboardManager在某个页面取消键盘上面的Toolbar

    使用IQKeyboardManager的时候,如果想在某个页面取消键盘上面的Toolbar,请使用如下方法,按控制器去操作 // 取消IQKeyboardManager Toolbar [[IQKey ...

  8. 键盘上各键对应的ASCII码与扫描码

    键盘上各键对应的ASCII码与扫描码 vbKeyLButton 0x1 鼠标左键vbKeyRButton 0x2 鼠标右键vbKeyCancel 0x3 CANCEL 键vbKeyMButton 0x ...

  9. 笔记本键盘上没有break键的解决方案

    django在Windows上调试需要用ctrl+break终止服务器……笔记本键盘上没有break好尴尬…… 在百度搜了很多都没有找到,最后终于在谷歌上找到了英文版的解决方案. starting o ...

随机推荐

  1. Xcode磁盘空间大清理(转)

    Xcode磁盘空间大清理 我的设备是Macbook Air 13’ Mid 2011,128G SSD.最近开始有些存储压力了,用Clean My Mac清理一部分旧文件后,决定对Xcode动手. 移 ...

  2. li颜色特效

    <!DOCTYPE html><html xmlns="http://www.w3.org/1999/xhtml"><head>    < ...

  3. ajax开发模拟后端数据接口

    在做前端开发的时候,特别是一些业务逻辑集中在前端的开发中.我们经常需要自己来模拟获取到后台接口的数据.为什么要模拟?可能后台接口还没有开发完成,可能后台还没有数据返回,可能...等等原因.曾经,我也尝 ...

  4. Jersey(1.19.1) - Security

    Security information is available by obtaining the SecurityContext using @Context, which is essentia ...

  5. C#_简单Excel导入

    引用程序集 Microsoft.Office.Core Microsoft.Office.Interop.Excel using System; using System.Collections.Ge ...

  6. Cocos2d-x加速度计实例:运动的小球

    下面我们通过一个实例介绍一下如果通过层加速度计事件实现访问加速度计.该实例场景如下图所示,场景中有一个小球,当我们把移动设备水平放置,屏幕向上,然后左右晃动移动设备来改变小球的位置. 下面我们再看看具 ...

  7. SharePoint Server 2013介绍v2

    SharePoint Server 2013介绍v2 http://wenku.baidu.com/link?url=rNYYoDmHcXmqhzOeA1sln5cS2xcnABYycBuz8Z4Oq ...

  8. OpenGL7-3快速绘制(索引方式)

    代码下载#include "CELLWinApp.hpp"#include <gl/GLU.h>#include <assert.h>#include &l ...

  9. Comparator和Comparable

    java.util 接口 Comparator<T>   compare int compare(T o1, T o2) 比较用来排序的两个参数.根据第一个参数小于.等于或大于第二个参数分 ...

  10. 关于arcgis发布wfs问题

    博客地址http://www.cnblogs.com/shizhongtao/p/3453594.html 官方文档中有这么一段描述: 从地图创建 WFS 服务 您 可以从 ArcMap 地图文档 ( ...