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. day12<常见对象+>

    常见对象(Scanner的概述和方法介绍) 常见对象(Scanner获取数据出现的小问题及解决方案) 常见对象(String类的概述) 常见对象(String类的构造方法) 常见对象(String类的 ...

  2. Matlab入门学习(程序设计)

    一.循环(for,while) for循环: for i=begin:step:end ...... end while循环: while condition ...... end 二.分枝(if,i ...

  3. Python迭代器,生成器--精华中的精华

    1. 迭代器 迭代器是访问集合元素的一种方式.迭代器对象从集合的第一个元素开始访问,直到所有的元素被访问完结束.迭代器只能往前不会后退,不过这也没什么,因为人们很少在迭代途中往后退.另外,迭代器的一大 ...

  4. 在JavaScript中使用json.js:Ajax项目之POST请求(异步)

    经常在百度搜索框输入一部分关键词后,弹出候选关键热词.现在我们就用Ajax技术来实现这一功能. 一.下载json.js文件 百度搜一下,最好到json官网下载,安全起见. 并与新建的两个文件部署如图 ...

  5. 详解MySQL基准测试和sysbench工具

    前言 作为一名后台开发,对数据库进行基准测试,以掌握数据库的性能情况是非常必要的.本文介绍了MySQL基准测试的基本概念,以及使用sysbench对MySQL进行基准测试的详细方法. 文章有疏漏之处, ...

  6. 【BZOJ】1015 [JSOI2008]星球大战starwar(并查集+离线处理)

    Description 很久以前,在一个遥远的星系,一个黑暗的帝国靠着它的超级武器统治者整个星系.某一天,凭着一个偶然的机遇,一支反抗军摧毁了帝国的超级武器,并攻下了星系中几乎所有的星球.这些星球通过 ...

  7. The Super Powers

    The Super Powers Time Limit: 1000MS   Memory Limit: Unknown   64bit IO Format: %lld & %llu [Subm ...

  8. 记录一下从懵懂到理解RESTful的过程

    前言 Spring+SpringMVC+MyBatis+easyUI整合进阶篇(一)设计一套好的RESTful API Spring+SpringMVC+MyBatis+easyUI整合进阶篇(二)R ...

  9. HDU1142 A Walk Through the Forest(最短路+DAG)

    A Walk Through the Forest Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/O ...

  10. Java面向对象 继承(下)

     Java面向对象   继承(下) 知识概要:               (1)抽象类 1.1 抽象类概述                            1.2 抽象类的特点       ...