2015-2016 ACM-ICPC, NEERC, Southern Subregional Contest J Cleaner Robot
Cleaner RobotCrawling in process... Crawling failed Time Limit:2000MS Memory Limit:524288KB 64bit IO Format:%I64d & %I64u
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:
- clean the current cell which a cleaner robot is in;
- 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;
- 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
2 3
U..
.*.
4
4 4
R...
.**.
.**.
....
12
3 4
***D
..*.
*...
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的更多相关文章
- 2018-2019 ICPC, NEERC, Southern Subregional Contest
目录 2018-2019 ICPC, NEERC, Southern Subregional Contest (Codeforces 1070) A.Find a Number(BFS) C.Clou ...
- Codeforces 2018-2019 ICPC, NEERC, Southern Subregional Contest
2018-2019 ICPC, NEERC, Southern Subregional Contest 闲谈: 被操哥和男神带飞的一场ACM,第一把做了这么多题,荣幸成为7题队,虽然比赛的时候频频出锅 ...
- 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 ...
- Codeforces1070 2018-2019 ICPC, NEERC, Southern Subregional Contest (Online Mirror, ACM-ICPC Rules, Teams Preferred)总结
第一次打ACM比赛,和yyf两个人一起搞事情 感觉被两个学长队暴打的好惨啊 然后我一直做傻子题,yyf一直在切神仙题 然后放一波题解(部分) A. Find a Number LINK 题目大意 给你 ...
- codeforce1070 2018-2019 ICPC, NEERC, Southern Subregional Contest (Online Mirror, ACM-ICPC Rules, Teams Preferred) 题解
秉承ACM团队合作的思想懒,这篇blog只有部分题解,剩余的请前往星感大神Star_Feel的blog食用(表示男神汉克斯更懒不屑于写我们分别代写了下...) C. Cloud Computing 扫 ...
- 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, ...
- 2018.10.20 2018-2019 ICPC,NEERC,Southern Subregional Contest(Online Mirror, ACM-ICPC Rules)
i207M的“怕不是一个小时就要弃疗的flag”并没有生效,这次居然写到了最后,好评=.= 然而可能是退役前和i207M的最后一场比赛了TAT 不过打得真的好爽啊QAQ 最终结果: 看见那几个罚时没, ...
- 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$ 思路: 定义一个二元组$< ...
- 【*2000】【2018-2019 ICPC, NEERC, Southern Subregional Contest C 】Cloud Computing
[链接] 我是链接,点我呀:) [题意] [题解] 我们可以很容易知道区间的每个位置有哪些安排可以用. 显然 我们优先用那些花费的钱比较少的租用cpu方案. 但一个方案可供租用的cpu有限. 我们可以 ...
随机推荐
- JDK8-废弃永久代(PermGen)迎来元空间(Metaspace)
1.背景 2.为什么废弃永久代(PermGen) 3.深入理解元空间(Metaspace) 4.总结 ========正文分割线===== 一.背景 1.1 永久代(PermGen)在哪里? 根据,h ...
- Spring框架(一)
Spring: Spring是一个开源框架,Spring是于2003 年兴起的一个轻量级的Java 开发框架,由 Rod Johnson在其著作 Expert One-On-One J2EE Deve ...
- 为什么你需要将代码迁移到ASP.NET Core 2.0?
随着 .NET Core 2.0 的发布,.NET 开源跨平台迎来了新的时代.开发者们可以选择使用命令行.个人喜好的文本编辑器.Visual Studio 2017 15.3 和 Visual Stu ...
- Postman高级应用——流程控制、调试、公共函数、外部数据文件
postman客户端下载地址:https://www.getpostman.com/apps 目录 流程控制 调试 公共函数 外部数据文件 流程控制 流程控制简言之就是设置接口的执行顺序,流程控制只有 ...
- 小符号反映大问题,Shell中下划线_与变量的关系。
之前写过一个根据日期和时间自动命名文件名的时候遇到一个问题. #! /bin/bash read -p "please input the filename:" filename ...
- vector 利用swap 函数进行内存的释放 vector<int>().swap
首先,vector与deque不同,其内存占用空间只会增长,不会减小.比如你首先分配了10,000个字节,然后erase掉后面9,999个,则虽然有效元素只有一个,但是内存占用仍为10,000个.所有 ...
- Linux入门之常用命令(6)Bash命令重定向 管线命令
命令重定向 将目前所得数据转移到其他地方 > 将输出结果导入文件 如 ls -l / >test (1)若test文件不存在则创建 (2)若test文件存在 清空后写入 > ...
- Suneast & Daxia (规律)
Suneast & Daxia Time Limit: 1000MS Memory Limit: 32768KB 64bit IO Format: %I64d & %I64u ...
- 1289 大鱼吃小鱼 1305 Pairwise Sum and Divide 1344 走格子 1347 旋转字符串 1381 硬币游戏
1289 大鱼吃小鱼 有N条鱼每条鱼的位置及大小均不同,他们沿着X轴游动,有的向左,有的向右.游动的速度是一样的,两条鱼相遇大鱼会吃掉小鱼.从左到右给出每条鱼的大小和游动的方向(0表示向左,1表示向右 ...
- MongoDB的全文检索(Text Search)功能
自己的项目中用到了mongodb,需要做一个搜索功能,刚开始不知道怎么搞,查了mongodb有个全文检索功能. 全文检索分为两步 第一,建立索引 db.stores.createIndex( { na ...