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. poj 2195 二分图最优匹配 或 最小费用最大流

    就是最基本的二分图最优匹配,将每个人向每个房子建一条边,权值就是他们manhattan距离.然后对所有权值取反,求一次最大二分图最优匹配,在将结果取反就行了. #include<iostream ...

  2. css3media响应式布局

    响应式布局可以为不同终端的用户提供更加舒适的界面和更好的用户体验,而且随着目前大屏幕移动设备的 普及,用"大势所趋"来形容也不为过.随着越来越多的设计师采用这个技术,我们不仅看到很 ...

  3. Magento事件机制 - Magento Event/Observer

    为了扩展Magento的功能,我们可以重写Magento的代码,但因为代码只能被重写一次,所以当多个模块需要重写同一部分的代码时,就会引起冲突,好在Magento提供了另一种扩展功能的方法:事件机制, ...

  4. 新增html元素的使用

    今天学习HTML5中新增元素的使用 (Ⅰ)新增主体结构元素 Section元素:用于对网站或应用程序中的内容进行分块. <section> <h1></h1> &l ...

  5. Jersey(1.19.1) - Building Responses

    Sometimes it is necessary to return additional information in response to a HTTP request. Such infor ...

  6. webBrowser1_DocumentCompleted不停被调用

    原文地址:http://blog.csdn.net/shuishenlong/article/details/7950576 关于DocumentCompleted事件,MSDN给出的解释是在文档加载 ...

  7. Agile.Net 组件式开发平台 - 权限管理组件

    RBAC原则       (1)最小权限原则之所以被RBAC所支持,是因为RBAC可以将其角色配置成其完成任务所需要的最小的权限集.       (2)责任分离原则可以通过调用相互独立互斥的角色来共同 ...

  8. knowlege experience

    The konwledge is you need learning some basic knowledge. The experience is you can use konwledge  ma ...

  9. sql中的触发器、视图、事务

    ·触发器(trigger) [触发器本质上还是一个存储过程,只不过不是用exe来调用执行,而是通过增删改数据库的操作] [触发器只对增.删.改有效] 触发器的格式 (instead of与for的区别 ...

  10. 169. Majority Element My Submissions Question

    Total Accepted: 95925 Total Submissions: 239241 Difficulty: Easy Given an array of size n, find the ...