bnuoj 31796 键盘上的蚂蚁(搜索模拟)
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 键盘上的蚂蚁(搜索模拟)的更多相关文章
- form表单提交和ajax表单提交,关于移动端如何通过软键盘上的【搜索】和【前进】进行提交操作
[文章来源]由于自己对于form研究甚少,所以一直用的都是AJAX进行提交,这次后台提出要用form提交,顺便深入研究一下:之前在做表单的时候,发现input可以通过设置不同的type属性,调用不同的 ...
- js 移动端写搜索时怎么调用软键盘上面的搜索按钮
这段时间一直在做移动端,所以遇到很多问题,现在很多网站在做移动端搜索的时候都不会在后面加一个搜索按钮,而是直接调用输入法上面的搜索搜索按钮进行搜索 input的一个新属性给我们提供非常方便的书写, 就 ...
- BZOJ1033:[ZJOI2008]杀蚂蚁antbuster(模拟)
Description 最近,佳佳迷上了一款好玩的小游戏:antbuster.游戏规则非常简单:在一张地图上,左上角是蚂蚁窝,右 下角是蛋糕,蚂蚁会源源不断地从窝里爬出来,试图把蛋糕搬回蚂蚁窝.而你的 ...
- 【NOIP 2011】Mayan游戏(搜索+模拟)
描述 Mayan puzzle是最近流行起来的一个游戏.游戏界面是一个7行5列的棋盘,上面堆放着一些方块,方块不能悬空堆放,即方块必须放在最下面一行,或者放在其他方块之上.**游戏通关是指在规定的步数 ...
- 如何使用alt键+数字键盘上的数字键打出特殊符号
如何使用alt键+数字键盘上的数字键打出特殊符号 有时当我需要画示意图说明一个问题,但是苦于没有合适的符号,因此,这篇博文将简单介绍一些特殊的符号方便自己以及大家使用. 实现原理很简单:所有的字符(包 ...
- 如何用Jquery判断在键盘上敲的哪个按键
有时候我们需要判断我们在键盘上敲了哪个键,这个需要查询下键盘上的键对应的值是多少,比如Enter键是13. 下面是Jquery代码,别忘了引用Jquery包哈. <script type=&qu ...
- IQKeyboardManager在某个页面取消键盘上面的Toolbar
使用IQKeyboardManager的时候,如果想在某个页面取消键盘上面的Toolbar,请使用如下方法,按控制器去操作 // 取消IQKeyboardManager Toolbar [[IQKey ...
- 键盘上各键对应的ASCII码与扫描码
键盘上各键对应的ASCII码与扫描码 vbKeyLButton 0x1 鼠标左键vbKeyRButton 0x2 鼠标右键vbKeyCancel 0x3 CANCEL 键vbKeyMButton 0x ...
- 笔记本键盘上没有break键的解决方案
django在Windows上调试需要用ctrl+break终止服务器……笔记本键盘上没有break好尴尬…… 在百度搜了很多都没有找到,最后终于在谷歌上找到了英文版的解决方案. starting o ...
随机推荐
- Ehcache(2.9.x) - API Developer Guide, Cache Event Listeners
About Cache Event Listeners Cache listeners allow implementers to register callback methods that wil ...
- Android开发中的PhoneGap基本使用
一.关于PhoneGap Phonegap是一款开源的开发框架,旨在让开发者使用HTML.Javascript.CSS等Web APIs开发跨平台的移动应用程序. 二.PhoneGap在Andro ...
- Android 第三方授权(微信篇)
0.申请开发者: https://open.weixin.qq.com/cgi-bin/frame?t=home/app_tmpl&lang=zh_CN 1.下载sdk包: https://o ...
- 第五篇、iOS常用的工具 app icon 、office文件格式互转、在线HTML编辑器、16、10进制互转
1.图片工厂,一键生成所以的应用图标 2.office文件转换格式 3.HTML在线编辑器 4.十六进制和十进制互转
- Xcode7中添加3DTouch
首先是插件SBShortcutMenuSimulator的安装 1.git clone https://github.com/DeskConnect/SBShortcutMenuSimulator.g ...
- Ajax和JSON基础
Ajax (核心是XMLHttpRequest对象) 1.XMLHttpRequest对象: request=new XMLHttpRequest() 支持Firefox opera Safari ...
- [zz] 安装PostGIS(Linux篇)
0.安装PostgreSQL数据库 参考安装PostgreSQL数据库(Linux篇). 1.安装proj4 #tar zxvf proj-4.8.0.tar.gz#cd proj-4.8.0#./c ...
- Contest1065 - 第四届“图灵杯”NEUQ-ACM程序设计竞赛(个人赛)E粉丝与分割平面
题目描述 在一个平面上使用一条直线最多可以将一个平面分割成两个平面,而使用两条直线最多可将平面分割成四份,使用三条直线可将平面分割成七份--这是个经典的平面分割问题,但是too simple,作为一个 ...
- 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 ...
- 《大话设计模式》学习笔记0:设计模式的原则 && UML类图
一.单一职责原则:就一个类而言,应该仅有一个引起它变化的原因. 如果一个类承担的职责过多,就等于把这些职责耦合在一起,一个职责的变化可能会削弱或者抑制这个类完成其他职责的能力.这种耦合会导致脆弱的设计 ...