博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
2015-2016 ACM-ICPC, NEERC, Southern Subregional Contest J Cleaner Robot
阅读量:7032 次
发布时间:2019-06-28

本文共 3905 字,大约阅读时间需要 13 分钟。

Cleaner RobotCrawling in process... Crawling failed Time Limit:2000MS     Memory Limit:524288KB     64bit IO Format:%I64d & %I64u

Submit

Description

 

Input

 

Output

 

Sample Input

 

Sample Output

 

Hint

 

Description

Masha has recently bought a cleaner robot, it can clean a floor without anybody's assistance.

Schematically Masha's room is a rectangle, consisting of w × h square cells of size 1 × 1. Each cell of the room is either empty (represented by character '.'), or occupied by furniture (represented by character '*').

A cleaner robot fully occupies one free cell. Also the robot has a current direction (one of four options), we will say that it looks in this direction.

The algorithm for the robot to move and clean the floor in the room is as follows:

  1. clean the current cell which a cleaner robot is in;
  2. if the side-adjacent cell in the direction where the robot is looking exists and is empty, move to it and go to step 1;
  3. otherwise turn 90 degrees clockwise (to the right relative to its current direction) and move to step 2.

The cleaner robot will follow this algorithm until Masha switches it off.

You know the position of furniture in Masha's room, the initial position and the direction of the cleaner robot. Can you calculate the total area of the room that the robot will clean if it works infinitely?

Input

The first line of the input contains two integers, w and h (1 ≤ w, h ≤ 10) — the sizes of Masha's room.

Next w lines contain h characters each — the description of the room. If a cell of a room is empty, then the corresponding character equals '.'. If a cell of a room is occupied by furniture, then the corresponding character equals '*'. If a cell has the robot, then it is empty, and the corresponding character in the input equals 'U', 'R', 'D' or 'L', where the letter represents the direction of the cleaner robot. Letter 'U' shows that the robot is looking up according to the scheme of the room, letter 'R' means it is looking to the right, letter 'D' means it is looking down and letter 'L' means it is looking to the left.

It is guaranteed that in the given w lines letter 'U', 'R', 'D' or 'L' occurs exactly once. The cell where the robot initially stands is empty (doesn't have any furniture).

Output

In the first line of the output print a single integer — the total area of the room that the robot will clean if it works infinitely.

Sample Input

 
Input
2 3 U.. .*.
Output
4
Input
4 4 R... .**. .**. ....
Output
12
Input
3 4 ***D ..*. *...
Output
6

Sample Output

 

Hint

In the first sample the robot first tries to move upwards, it can't do it, so it turns right. Then it makes two steps to the right, meets a wall and turns downwards. It moves down, unfortunately tries moving left and locks itself moving from cell (1, 3) to cell (2, 3) and back. The cells visited by the robot are marked gray on the picture.

                                                                                                             

/*一个机器人遇到障碍物就会顺时针旋转90度,问你机器人活动区域最大是多少用v[i][j][d]记录用怎么样的状态进入这个点,如果下一次又出现,那么一定出现循环就可以停止了*/#include
#include
#include
#define N 12using namespace std; int n,m,cur=1;int dir[5][2]={-1,0,1,0,0,-1,0,1};//上下左右char mapn[N][N];int visit[N][N]={
0};//记录这个点来没来过int visitn[N][N][N]={
0};//记录这个点来过多少次int v(char ch){ if(ch=='U') return 0; if(ch=='D') return 1; if(ch=='L') return 2; if(ch=='R') return 3;}bool check(int x1,int y1){ if(x1<0||x1>=n||y1<0||y1>=m||mapn[x1][y1]=='*') return true; return false;}void dfs(int x,int y,int d){ if(visitn[x][y][d]) return ; visitn[x][y][d]=1; if(!visit[x][y]) cur++,visit[x][y]=1; if(d==0)//上 { int fx=x+dir[0][0]; int fy=y+dir[0][1]; if(check(fx,fy))//走不通 //cout<<"转向 "<
<<" "<
<

 

 

转载于:https://www.cnblogs.com/wuwangchuxin0924/p/5791131.html

你可能感兴趣的文章
详解Linux运维工程师必备技能
查看>>
[20181109]12c sqlplus rowprefetch参数5
查看>>
bupt summer training for 16 #1 ——简单题目
查看>>
【Udacity】朴素贝叶斯
查看>>
shader 讲解的第二天 把兰伯特模型改成半兰泊特模型 函数图形绘制工具
查看>>
python3.5安装Numpy、mayploylib、opencv等额外库
查看>>
优雅绝妙的Javascript跨域问题解决方案
查看>>
Java 接口技术 Interface
查看>>
函数草稿
查看>>
织梦系统学习:文章页当前位置的写法(自认对SEO有用)
查看>>
PHP经验——PHPDoc PHP注释的标准文档(翻译自Wiki)
查看>>
vue input输入框长度限制
查看>>
深入理解Java虚拟机(类加载机制)
查看>>
在500jsp错误页面获取错误信息
查看>>
iOS-CALayer遮罩效果
查看>>
为什么需要版本管理
查看>>
五、Dart 关键字
查看>>
React Native学习笔记(一)附视频教学
查看>>
记Promise得一些API
查看>>
javascript事件之调整大小(resize)事件
查看>>