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

【题意】:

  如题,注意大小写情况

【code】:

  1. #include <iostream>
  2. #include <stdio.h>
  3. #include <string.h>
  4. #include <ctype.h>
  5. #include <algorithm>
  6. #include <queue>
  7.  
  8. using namespace std;
  9.  
  10. struct Nod
  11. {
  12. int x,y,step;
  13. }nd1,nd2;
  14.  
  15. int step[][];
  16. char temp[];
  17. int cx[]={,-,,,,-}; //定义六个方向可以移动
  18. int cy[]={,,-,,-,};
  19. char str[][]={
  20. "`1234567890-=***",
  21. "*QWERTYUIOP[]\\**", //这里的反斜杠‘\’必须打两个进行转义
  22. "*ASDFGHJKL;'****",
  23. "*ZXCVBNM,./*****",
  24. "*** ********",
  25. };
  26.  
  27. int mark[][];
  28.  
  29. void BFS(int x,int y,int nx,int ny) //4 14 / 5 14
  30. {
  31. memset(mark,,sizeof(mark));
  32. nd1.x = x;
  33. nd1.y = y;
  34. nd1.step = ;
  35. char ch = str[x][y];
  36. step[ch][ch] = ;
  37. if(temp[ch]!=)
  38. {
  39. step[temp[ch]][temp[ch]]=;
  40. step[ch][temp[ch]]=;
  41. step[temp[ch]][ch]=;
  42. }
  43. mark[x][y]=;
  44. queue<Nod> Q;
  45. Q.push(nd1);
  46. while(!Q.empty())
  47. {
  48. nd2 = Q.front();
  49. Q.pop();
  50. int i;
  51. for(i=;i<;i++)
  52. {
  53. nd1.x = nd2.x + cx[i];
  54. nd1.y = nd2.y + cy[i];
  55. nd1.step = nd2.step + ;
  56. if(nd1.x>=&&nd1.x<nx&&nd1.y>=&&nd1.y<ny&&str[nd1.x][nd1.y]!='*'&&!mark[nd1.x][nd1.y])
  57. {
  58. mark[nd1.x][nd1.y]=;
  59. step[str[nd1.x][nd1.y]][ch]=nd1.step;
  60. if(temp[str[nd1.x][nd1.y]]!=)
  61. {
  62. step[temp[str[nd1.x][nd1.y]]][ch]=nd1.step;
  63. }
  64. if(temp[ch]!=)
  65. {
  66. step[str[nd1.x][nd1.y]][temp[ch]]=nd1.step;
  67. }
  68. if(temp[str[nd1.x][nd1.y]]!=&&temp[ch]!=)
  69. {
  70. step[temp[str[nd1.x][nd1.y]]][temp[ch]]=nd1.step;
  71. }
  72. Q.push(nd1);
  73. }
  74. }
  75. }
  76. }
  77.  
  78. void getStepArr()
  79. {
  80. memset(step,-,sizeof(step));
  81. char cc[]="CVBNM,";
  82. int i,j,k;
  83. for(i=;i<;i++)
  84. {
  85. for(j=;j<;j++)
  86. {
  87. char ch = str[i][j];
  88. if(ch!='*')
  89. {
  90. BFS(i,j,,);
  91. }
  92. }
  93. }
  94. //对空格键单独处理
  95. for(i=;i<;i++)
  96. {
  97. for(j=;j<;j++)
  98. {
  99. char ch = str[i][j];
  100. if(ch!='*')
  101. {
  102. int mins = ;
  103. for(k=;k<;k++)
  104. {
  105. if(mins>step[ch][cc[k]])
  106. {
  107. mins=step[ch][cc[k]];
  108. }
  109. }
  110. step[ch][' ']=mins+;
  111. step[' '][ch]=mins+;
  112. if(temp[ch]!=)
  113. {
  114. step[temp[ch]][' ']=mins+;
  115. step[' '][temp[ch]]=mins+;
  116.  
  117. }
  118. }
  119. }
  120. }
  121. }
  122.  
  123. char quer[];
  124.  
  125. int main()
  126. {
  127. memset(temp,,sizeof(temp));
  128. temp['`']='~';
  129. temp['']='!';
  130. temp['']='@';
  131. temp['']='#';
  132. temp['']='$';
  133. temp['']='%';
  134. temp['']='^';
  135. temp['']='&';
  136. temp['']='*';
  137. temp['']='(';
  138. temp['']=')';
  139. temp['-']='_';
  140. temp['=']='+';
  141. temp['[']='{';
  142. temp[']']='}';
  143. temp['\\']='|';
  144. temp[';']=':';
  145. temp['\'']='"';
  146. temp[',']='<';
  147. temp['.']='>';
  148. temp['/']='?';
  149. getStepArr();
  150. while(gets(quer))
  151. {
  152. int len = strlen(quer);
  153. int i,ans=;
  154. for(i=;i<len;i++) quer[i]=toupper(quer[i]);
  155. for(i=;i<len-;i++)
  156. {
  157. ans+=step[quer[i]][quer[i+]];
  158. }
  159. printf("%d\n",ans);
  160. }
  161. return ;
  162. }

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. Ehcache(2.9.x) - API Developer Guide, Cache Event Listeners

    About Cache Event Listeners Cache listeners allow implementers to register callback methods that wil ...

  2. Android开发中的PhoneGap基本使用

    一.关于PhoneGap Phonegap是一款开源的开发框架,旨在让开发者使用HTML.Javascript.CSS等Web APIs开发跨平台的移动应用程序.   二.PhoneGap在Andro ...

  3. Android 第三方授权(微信篇)

    0.申请开发者: https://open.weixin.qq.com/cgi-bin/frame?t=home/app_tmpl&lang=zh_CN 1.下载sdk包: https://o ...

  4. 第五篇、iOS常用的工具 app icon 、office文件格式互转、在线HTML编辑器、16、10进制互转

    1.图片工厂,一键生成所以的应用图标 2.office文件转换格式 3.HTML在线编辑器 4.十六进制和十进制互转

  5. Xcode7中添加3DTouch

    首先是插件SBShortcutMenuSimulator的安装 1.git clone https://github.com/DeskConnect/SBShortcutMenuSimulator.g ...

  6. Ajax和JSON基础

    Ajax (核心是XMLHttpRequest对象) 1.XMLHttpRequest对象: request=new XMLHttpRequest()  支持Firefox opera Safari  ...

  7. [zz] 安装PostGIS(Linux篇)

    0.安装PostgreSQL数据库 参考安装PostgreSQL数据库(Linux篇). 1.安装proj4 #tar zxvf proj-4.8.0.tar.gz#cd proj-4.8.0#./c ...

  8. Contest1065 - 第四届“图灵杯”NEUQ-ACM程序设计竞赛(个人赛)E粉丝与分割平面

    题目描述 在一个平面上使用一条直线最多可以将一个平面分割成两个平面,而使用两条直线最多可将平面分割成四份,使用三条直线可将平面分割成七份--这是个经典的平面分割问题,但是too simple,作为一个 ...

  9. vs2005_the breakpoint will not currently be hit. The source code is different from the original verison.

    公司开发只能用英文版的VS2005 (雅蠛蝶) Tool-->Options-->Debugging->General: 把Require source files to exact ...

  10. 《大话设计模式》学习笔记0:设计模式的原则 && UML类图

    一.单一职责原则:就一个类而言,应该仅有一个引起它变化的原因. 如果一个类承担的职责过多,就等于把这些职责耦合在一起,一个职责的变化可能会削弱或者抑制这个类完成其他职责的能力.这种耦合会导致脆弱的设计 ...