有一个M*N的矩阵,有一个会自动清洁的机器人,这个机器人会按照设定好的程序来打扫卫生,如果当前方向前面可以行走,那么直接走,如果不可以走那么会向右转动90度,然后回归上一步判断。求机器人最多能打扫的面积是多少。

分析:直接搜就行了.......

代码如下:

----------------------------------------------------------------------------------------------------------------

#include<stdio.h>
#include<string.h> const int MAXN = ; ///'U', 'R', 'D' 'L'
int dir[][] = { {-,},{,},{,},{,-} };
int M, N;
char G[MAXN][MAXN];
bool v[MAXN][MAXN][]; void DFS(int k, int x, int y, int &ans)
{
if(G[x][y] == '.')
{
ans += ;
G[x][y] = '#';
} for(int i=; i<; i++)
{
int nx = x+dir[(i+k)%][];
int ny = y+dir[(i+k)%][]; if(nx>=&&nx<M && ny>=&&ny<N && G[nx][ny]!='*')
{
if(v[nx][ny][(i+k)%] == true)
break;
v[nx][ny][(i+k)%] = true;
DFS((i+k)%, nx, ny, ans);
break;
}
}
} int main()
{
while(scanf("%d%d", &M, &N) != EOF)
{
memset(v, , sizeof(v)); int x, y, op; for(int i=; i<M; i++)
{
scanf("%s", G[i]);
for(int j=; j<N; j++)
{
if(G[i][j] == 'U')
op = , x=i, y=j;
if(G[i][j] == 'R')
op = , x=i, y=j;
if(G[i][j] == 'D')
op = , x=i, y=j;
if(G[i][j] == 'L')
op = , x=i, y=j;
}
} int ans = ;
DFS(op, x, y, ans); printf("%d\n", ans);
} return ;
}

Cleaner Robot - CodeForces 589J(搜索)的更多相关文章

  1. 2015-2016 ACM-ICPC, NEERC, Southern Subregional Contest J Cleaner Robot

    Cleaner RobotCrawling in process... Crawling failed Time Limit:2000MS     Memory Limit:524288KB     ...

  2. CodeForces - 589J —(DFS)

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

  3. CodeForces 589J Cleaner Robot

    题目链接 题意:一个机器人打扫卫生,URDL代表初始时机器人面对的方向上右下左. ' . ' 代表可以打扫的, ' * ' 代表家具,如果机器人遇到家具就顺时针转90度,问机器人能打扫多少面积. 题解 ...

  4. CodeForces 589J Cleaner Robot (DFS,或BFS)

    题意:给定n*m的矩阵,一个机器人从一个位置,开始走,如果碰到*或者边界,就顺时针旋转,接着走,问你最后机器人最多能走过多少格子. 析:这个题主要是题意读的不大好,WA了好几次,首先是在*或者边界才能 ...

  5. CodeForces - 589J(DFS)

    题目链接:http://codeforces.com/problemset/problem/589/J 题目大意:一个机器人打扫一个密闭的房间,房间由一个矩形构成,'*'表示家具,'.'表示该位置为空 ...

  6. Robot Framework——百度搜索

     1.创建项目 选择菜单栏file----->new Project 右键点击新建Project,选择new Suite 选项. 右键点击新建测试Suite,选择new Test Case. 完 ...

  7. Broken robot CodeForces - 24D (概率DP)

    You received as a gift a very clever robot walking on a rectangular board. Unfortunately, you unders ...

  8. 2019河北省大学生程序设计竞赛(重现赛) L题-smart robot(深度优先搜索)

    题目链接:https://ac.nowcoder.com/acm/contest/903/L 题意:给你 n * n的方阵,你可以从任意一个数字开始走,可以走上下左右四个方向,走过的数字会被拼合,拼合 ...

  9. Codeforces 754A(搜索)

    设s[i][j]为序列i到j的和,当s[i][j]≠0时,即可从i跳到j+1.目标为从1跳到n+1,所以按照题意暴力即可. #include <bits/stdc++.h> using n ...

随机推荐

  1. 使用自定义 jQuery 插件的一个选项卡Demo

    前几天闲着没事,想着编写一个 jQuery 插件,或许这将是一个美好的开始. 这里是html页面: <!DOCTYPE html> <html lang="en" ...

  2. ci 用本身 email 类发 email

    //比如 在控制器用 email 方法发送邮件 //用126的smtp 发送,示例邮件为 myemail@126.com 密码为 password public function email() { ...

  3. linux环境下安装php扩展

    本文只提供源码安装的方法(已安装pcntl为例) 其他方法请参考:http://doc3.workerman.net/appendices/install-extension.html 1.利用php ...

  4. React新接触

    html5页面的开始引入: <script src="../build/react.js"></script>   <!--核心库--> < ...

  5. textarea 超过字数

    <textarea name="></textarea> <div id="statementRowChk"></div> ...

  6. session阻塞机制,解决方法

    session从生成到读取,或从生成到写入都出现锁定的情况. 1.session_start();session_commit(); 2.session_start();session_write_c ...

  7. python学习--string

    1\string are immutable, which means you can't change an existing string. >>>greeting = 'Hel ...

  8. Python正则表达式学习

    1.Python的正则表达式需要用到re模块,有两个方法:match和search,match从第一个字符串开始匹配,search从任意字符串开始匹配,所以match比search严格. 如果匹配成功 ...

  9. Remark of BLENDFUNCTION from MSDN

    Remarks When the AlphaFormat member is AC_SRC_ALPHA, the source bitmap must be 32 bpp. If it is not, ...

  10. STM32之SD卡

    目录 一.SD卡概述 1.定义 2.容量等级 3.SD卡框图 4.SD卡与TF卡的区别 二. SD卡内部结构 1. SD卡内部结构简图 2. 存储阵列结构图 3.Buffer 4.“存储阵列Block ...