题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1035

稍微有点复杂,但是只要模拟出来应该就能过了。

#include <iostream>
using namespace std;class node
{
public:char instruct;int stepId;
};const int SIZE = 12;
char aLine[SIZE];
node map[SIZE][SIZE];void move(int &curRow,int &curCol,char instruct)
{switch (instruct){case 'N':curRow --;break;case 'S':curRow ++;break;case 'W':curCol --;break;case 'E':curCol ++;break;}
}//计算从起始点(1,initCol)走到(endRow,endCol)需要走多个步
int countStepBeforeExit(int initCol,int endRow,int endCol)
{int curRow = 1,curCol = initCol;int stepBeforeExit = 0;while (1){if (curRow == endRow && curCol == endCol)break;stepBeforeExit ++;move(curRow,curCol,map[curRow][curCol].instruct);}return stepBeforeExit;
}//判断(curRow,curCol)是否出界
int judgeExit(int curRow,int curCol,int row,int col)
{if (curRow < 1 || curRow > row || curCol < 1 || curCol > col)return 1;return 0;
}int main ()
{int row,col,initCol;while (scanf("%d%d%d",&row,&col,&initCol) != -1){if (row == 0 && col == 0 && initCol == 0)break;//初始化for (int i = 0;i < SIZE;i ++)for (int j = 0;j < SIZE;j ++)map[i][j].stepId = 0;for (int i = 1;i <= row;i ++){scanf("%s",aLine);for (int j = 1;j <= col;j ++){map[i][j].instruct = aLine[j - 1];}}int isExit = 1,stepBeforeExit,stepLoop;int preRow,preCol;preRow = preCol = -1;int curRow = 1,curCol = initCol;int stepCount = 0;while (1){//这一点之前曾走过,说明出现了回路if (map[curRow][curCol].stepId != 0){stepLoop = map[preRow][preCol].stepId - map[curRow][curCol].stepId + 1;//计算走到当前点的前一点用了多少个step(s)stepBeforeExit = countStepBeforeExit(initCol,curRow,curCol);//最后没能走出去isExit = 0;break;}else if (judgeExit(curRow,curCol,row,col)){isExit = 1;stepBeforeExit = map[preRow][preCol].stepId;break;}stepCount ++;map[curRow][curCol].stepId = stepCount;preRow = curRow , preCol = curCol;//走到下一点
            move(curRow,curCol,map[curRow][curCol].instruct);    }//能走出去if (isExit)printf("%d step(s) to exit\n",stepBeforeExit);elseprintf("%d step(s) before a loop of %d step(s)\n",stepBeforeExit,stepLoop);}return 0;
}

转载于:https://www.cnblogs.com/peaceful-andy/archive/2012/08/19/2646757.html

HDOJ 1035 模拟 水相关推荐

  1. HDOJ 1082 模拟 水

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1082 题目大意:有若干个矩阵,输入数据给出其行,列数.再给若干个计算矩阵乘法的顺序,求出以此顺序来计算 ...

  2. 洛谷 1563 玩具谜题——模拟水题

    题目:https://www.luogu.org/problemnew/show/P1563 模拟水题. #include<iostream> #include<cstdio> ...

  3. 【CCCC】L2-027 名人堂与代金券 (25分),模拟水题

    problem L2-027 名人堂与代金券 (25分) 对于在中国大学MOOC(http://www.icourse163.org/ )学习"数据结构"课程的学生,想要获得一张合 ...

  4. 关于Green-Kubo方法模拟水的粘度

    关于Green-Kubo方法模拟水的粘度 求问有没有大神用lammps做过水的模拟? 我现在改编了一下manual里面计算液氩粘度的那个算例,来模拟水的粘度,300k下得到的结果是0.2mPa.s,查 ...

  5. 【Unity Shader实例】 水体WaterEffect(二) 用贴图和uv动画模拟水效

    Unity Shader实现简单水体效果 效果展示 原理 用贴图和uv动画模拟水效实现"假"水. 设计 找一张水波的贴图,处理它的uv值,让贴图流动起来.这样就用静态纹理和uv动画 ...

  6. poj 3095 Linear Pachinko 模拟水题

    题意: 给一个字符串,求小球随机放在上面进洞或到达两边之外的期望. 分析 水题,直接模拟. 代码: //poj 3095 //sep9 #include <iostream> using ...

  7. 游戏制作之路(56)模拟水

    前面学习了创建风,可以吹动树,但是大自然里还有水,比如湖.大海等等.这样湖光山色,就更符自然世界里的景象了.下面就来学习怎么样创建水的物体,比如小水池,小湖,大海等.先创建一个简单的地形,像前面的例子 ...

  8. 牛客~~打篮球~~~模拟水题

    链接:https://www.nowcoder.com/acm/contest/118/D 来源:牛客网 题目描述 1, 2, 3在打篮球, 可是二打一总是不公平的, 于是他们决定一对一,另一个人在边 ...

  9. Intelligent Factorial Factorization LightOJ - 1035(水题)

    就是暴力嘛...很水的一个题... 不好意思交都... #include <iostream> #include <cstdio> #include <sstream&g ...

  10. 【HDU - 1326】Box of Bricks(模拟水题)

    题干: Little Bob likes playing with his box of bricks. He puts the bricks one upon another and builds ...

最新文章

  1. 怎么把写好的python代码打包成exe-【Python之点到为止】如何优雅的将你的代码打包成EXE...
  2. Windos消息驱动
  3. 2011阿里巴巴集团实习生招聘笔试题 CC++
  4. 【转】光栅化操作阶段
  5. git基础用法(一)
  6. 局域网IP地址查看软件V1.2使用教程 Python办公自动化
  7. 【Paper-Attack Defense】Adversarial Label-Flipping Attack and Defense for Graph Neural Networks
  8. Python模拟随机漫步
  9. ibm服务器网络安装系统安装系统安装教程,IBM服务器系统安装步骤.doc
  10. 关闭word 2010时每次都提示:所做更改会影响共用模板Normal.dotm
  11. vnc远程桌面精灵,七款让人爱不释手的vnc远程桌面精灵
  12. stbc 多发送天线 matlab,系统天线论文,关于基于STBC的MIMO-OFDM系统误码性能仿真相关参考文献资料-免费论文范文...
  13. Bluecoat:搭建未来知识产权管理构架
  14. vb中产生随机数经典实例分析
  15. Windows如何强制关闭电脑全部代理
  16. python作排产计划表_排产计划表
  17. 用户画像(一):我对用户画像的理解
  18. Redis各版本的特性及架构
  19. java windows 打印机_使用Java中的客户端计算机打印机(不是部署应用程序的服务器)进行打印...
  20. HDU 1846-Brave Game(巴什博弈-SG函数)

热门文章

  1. tcp/ip发送接收总体框架
  2. presto 使用 部署_探秘Presto+Alluxio高效云端SQL查询
  3. Android 多媒体开发学习之撕衣服
  4. linux下verilog功能验证,Verilog 条件语句介绍
  5. 复制VIM编辑的文件和代码到别的地方
  6. SylixOS pci 设备驱动开发
  7. 51Nod 1637 幸运数字转换(思维)
  8. 火狐查看html的隐藏域,IE/火狐/Chrome操作display:none对象所遇问题解答
  9. n的阶乘末尾含0的个数
  10. android 发布版本证书,Android Studio 获取发布版和测试版证书SHA1的两种方式