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

Submit Status

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<bits/stdc++.h>
#include<string.h>
#include<stdio.h>
#define N 12
using namespace std;
int n,m,cur=;
int dir[][]={-,,,,,-,,};//上下左右
char mapn[N][N];
int visit[N][N]={};//记录这个点来没来过
int visitn[N][N][N]={};//记录这个点来过多少次
int v(char ch)
{
if(ch=='U') return ;
if(ch=='D') return ;
if(ch=='L') return ;
if(ch=='R') return ;
}
bool check(int x1,int y1)
{
if(x1<||x1>=n||y1<||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]=;
if(!visit[x][y])
cur++,visit[x][y]=;
if(d==)//上
{
int fx=x+dir[][];
int fy=y+dir[][];
if(check(fx,fy))//走不通
//cout<<"转向 "<<x<<" "<<y<<endl;
dfs(x,y,);
else//能走通
dfs(fx,fy,);
}
else if(d==)//下
{
int fx=x+dir[][];
int fy=y+dir[][];
if(check(fx,fy))//走不通
//cout<<"转向 "<<x<<" "<<y<<endl;
dfs(x,y,);
else//能走通
dfs(fx,fy,);
}
else if(d==)//左
{
int fx=x+dir[][];
int fy=y+dir[][];
//cout<<x<<" "<<y<<endl;
//cout<<fx<<" "<<fy<<endl;
//return ;
if(check(fx,fy))//走不通
//cout<<"转向 "<<x<<" "<<y<<endl;
dfs(x,y,);
else//能走通
dfs(fx,fy,);
}
else if(d==)//右
{
int fx=x+dir[][];
int fy=y+dir[][];
if(check(fx,fy))//走不通
//cout<<"转向 "<<x<<" "<<y<<endl;
dfs(x,y,);
else//能走通
dfs(fx,fy,);
}
}
int main()
{
//freopen("in.txt","r",stdin);
scanf("%d%d",&n,&m);
//cout<<n<<" "<<m<<endl;
getchar();
int x,y;
cur=;
for(int i=;i<n;i++)
{
for(int j=;j<m;j++)
{
scanf("%c",&mapn[i][j]);
if(mapn[i][j]=='U'||mapn[i][j]=='D'||mapn[i][j]=='L'||mapn[i][j]=='R')
x=i,y=j;
}
scanf("\n");
}
//for(int i=0;i<n;i++)
// cout<<mapn[i]<<endl;
visit[x][y]=;
dfs(x,y,v(mapn[x][y]));
//for(int i=0;i<n;i++)
//{
// for(int j=0;j<m;j++)
// cout<<visit[i][j]<<" ";
// cout<<endl;
//}
printf("%d\n",cur);
return ;
}

2015-2016 ACM-ICPC, NEERC, Southern Subregional Contest J Cleaner Robot的更多相关文章

  1. 2018-2019 ICPC, NEERC, Southern Subregional Contest

    目录 2018-2019 ICPC, NEERC, Southern Subregional Contest (Codeforces 1070) A.Find a Number(BFS) C.Clou ...

  2. Codeforces 2018-2019 ICPC, NEERC, Southern Subregional Contest

    2018-2019 ICPC, NEERC, Southern Subregional Contest 闲谈: 被操哥和男神带飞的一场ACM,第一把做了这么多题,荣幸成为7题队,虽然比赛的时候频频出锅 ...

  3. 2018-2019 ICPC, NEERC, Southern Subregional Contest (Online Mirror) Solution

    从这里开始 题目列表 瞎扯 Problem A Find a Number Problem B Berkomnadzor Problem C Cloud Computing Problem D Gar ...

  4. Codeforces1070 2018-2019 ICPC, NEERC, Southern Subregional Contest (Online Mirror, ACM-ICPC Rules, Teams Preferred)总结

    第一次打ACM比赛,和yyf两个人一起搞事情 感觉被两个学长队暴打的好惨啊 然后我一直做傻子题,yyf一直在切神仙题 然后放一波题解(部分) A. Find a Number LINK 题目大意 给你 ...

  5. codeforce1070 2018-2019 ICPC, NEERC, Southern Subregional Contest (Online Mirror, ACM-ICPC Rules, Teams Preferred) 题解

    秉承ACM团队合作的思想懒,这篇blog只有部分题解,剩余的请前往星感大神Star_Feel的blog食用(表示男神汉克斯更懒不屑于写我们分别代写了下...) C. Cloud Computing 扫 ...

  6. 2018-2019 ICPC, NEERC, Southern Subregional Contest (Online Mirror, ACM-ICPC Rules, Teams Preferred)

    A. Find a Number 找到一个树,可以被d整除,且数字和为s 记忆化搜索 static class S{ int mod,s; String str; public S(int mod, ...

  7. 2018.10.20 2018-2019 ICPC,NEERC,Southern Subregional Contest(Online Mirror, ACM-ICPC Rules)

    i207M的“怕不是一个小时就要弃疗的flag”并没有生效,这次居然写到了最后,好评=.= 然而可能是退役前和i207M的最后一场比赛了TAT 不过打得真的好爽啊QAQ 最终结果: 看见那几个罚时没, ...

  8. 2018-2019 ICPC, NEERC, Southern Subregional Contest (Online Mirror, ACM-ICPC Rules, Teams Preferred) Solution

    A. Find a Number Solved By 2017212212083 题意:$找一个最小的n使得n % d == 0 并且 n 的每一位数字加起来之和为s$ 思路: 定义一个二元组$< ...

  9. 【*2000】【2018-2019 ICPC, NEERC, Southern Subregional Contest C 】Cloud Computing

    [链接] 我是链接,点我呀:) [题意] [题解] 我们可以很容易知道区间的每个位置有哪些安排可以用. 显然 我们优先用那些花费的钱比较少的租用cpu方案. 但一个方案可供租用的cpu有限. 我们可以 ...

随机推荐

  1. python基础之七种运算符

    废话不多说,上节说的是数据类型,本篇讲讲数据运算. 在算式"1+2"中,"1"和"2"被称为操作数,"+"被称为运算符 ...

  2. Spring框架(一)

    Spring: Spring是一个开源框架,Spring是于2003 年兴起的一个轻量级的Java 开发框架,由 Rod Johnson在其著作 Expert One-On-One J2EE Deve ...

  3. React——组件的生命周期函数

    每一个组件都有一些生命周期函数. 当组件实例被创建并且会插入到DOM中,下面这些函数会被调用 constructor componentWillMount render componentDidMou ...

  4. Symbol

    ES5 的对象属性名都是字符串,这容易造成属性名的冲突.比如,你使用了一个他人提供的对象,但又想为这个对象添加新的方法(mixin 模式),新方法的名字就有可能与现有方法产生冲突.如果有一种机制,保证 ...

  5. hdu2157矩阵快速幂

    How many ways?? Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) ...

  6. c#入门基础笔记

    1.1:.NET与C# 1.1.1:.NET概述与C#应用 .NET是位于WINDOWs平台的一种技术.包含能在.NET FRAMwork平台运行的所有编程. 1.1.2:IDE环境 微软退出强大的平 ...

  7. Linux查找和筛选工具

    本文为原创文章,转载请标明出处 目录 文件名通配符 单字符匹配元字符 ? 多字符匹配元字符 * 字符范围匹配符 [] 排除范围匹配符 [!] 命令中的正则表达式 单字符匹配符 . 单字符或字符串重复匹 ...

  8. 配置和启动Kubernetes服务

    安装etcd服务 下载安装包 wget https://github.com/coreos/etcd/releases/download/v3.1.3/etcd-v3.1.3-linux-amd64. ...

  9. Python自学笔记-递归函数(来自廖雪峰的官网Python3)

    感觉廖雪峰的官网http://www.liaoxuefeng.com/里面的教程不错,所以学习一下,把需要复习的摘抄一下. 以下内容主要为了自己复习用,详细内容请登录廖雪峰的官网查看.   递归函数 ...

  10. 【转】DSCP 与IP 优先级IP优先级

    在IPv4的报文头中,TOS字段是1字节,如下图所示.根据RFC1122的定义,IP优先级(IPPrecedence)使用最高3比特(第0-2比特).+++++++++++++++++++++++++ ...