传送门

#1290 : Demo Day

时间限制:10000ms
单点时限:1000ms
内存限制:256MB

描述

You work as an intern at a robotics startup. Today is your company's demo day. During the demo your company's robot will be put in a maze and without any information about the maze, it should be able to find a way out.

The maze consists of N * M grids. Each grid is either empty(represented by '.') or blocked by an obstacle(represented by 'b'). The robot will be release at the top left corner and the exit is at the bottom right corner.

Unfortunately some sensors on the robot go crazy just before the demo starts. As a result, the robot can only repeats two operations alternatively: keep moving to the right until it can't and keep moving to the bottom until it can't. At the beginning, the robot keeps moving to the right.

rrrrbb..
...r.... ====> The robot route with broken sensors is marked by 'r'.
...rrb..
...bb...

While the FTEs(full-time employees) are busy working on the sensors, you try to save the demo day by rearranging the maze in such a way that even with the broken sensors the robot can reach the exit successfully. You can change a grid from empty to blocked and vice versa. So as not to arouse suspision, you want to change as few grids as possible. What is the mininum number?

输入

Line 1: N, M.

Line 2-N+1: the N * M maze.

For 20% of the data, N * M <= 16.

For 50% of the data, 1 <= N, M <= 8.

For 100% of the data, 1<= N, M <= 100.

输出

The minimum number of grids to be changed.

样例输入
4 8
....bb..
........
.....b..
...bb...
样例输出
1
1290 Demo Day AC G++ 0ms 0MB 1分钟前 查看

题解:

转自:http://www.cnblogs.com/acSzz/p/5362865.html

题目的意思是:
给你一个矩阵由‘.’和'b'组成 ‘.’表示可以走,'b'表示障碍物,机器人只能往右走直到不能走(碰到障碍物或者到头)和往下走直到不能走,两个方向,起始点是左上角,出口是右下角,为了机器人
能够走到出口,你可以将'.'变为'b', 也可以将'b'变为'.',,求为了使机器人走到出口,最少的变换次数。
(机器人从起点,一开始是往右走的,记住!!!!!!!) 思路:
应该算是动态规划吧,对于每一个点,到达这个点只能是经过上方点,或者从左方点到达该点,那么对于每一个点,一开始想的是用f[i][j],表示到达(i,j)需要变动的最小次数,但是发现到达每一个点是有方向的
,而且如果只用f[i][j],表示到达(i,j)的最小变动次数,不知道方向的话是无法递推下一个点的,所以,
我们用up[i][j],表示从上方到达该点需要变动的最小次数,r[i][j]表示从左方到达该点需要变动的最小次数,
  (i-1,j) (i - 1,j+1)
  (i,j)  
 对于up[i][j],可以是从左方到达(i-1, j),再到达(i,j),但此时(i-1, j+1)必须为'b'或者边界,也可以从上方到达(i-1,j)再到达(i,j);
还有就是如果(i,j)本身为'b'的话,则需要up[i][j]+1; up[i-1][j]
up[i][j] = min
r[i-1][j] + 1(如果(i-1,j)不为‘b’或者边界则需要+1); 同理可得: up[i][j-1] (+1) (如果(i+1,j-1)不为'b'或者边界,则需要+1)
r[i][j] = min
r[i][j-1] 为了处理方便在输入时,在矩阵的最右边和最下边添加了一行,一列'b'; 代码: 核心转移方程:
int dp[N][N][];    //0xia,1you
int checkxia(int x,int y)
{
if(x == n) return ;
if(s[x+][y] == 'b') return ;
else return ;
} int checkyou(int x,int y)
{
if(y == m) return ;
if(s[x][y+] == 'b') return ;
else return ;
}
fxia = checkxia(i,j);
fyou = checkyou(i,j); dp[i][j][] += min(dp[i-][j][],dp[i][j-][] + fyou);
dp[i][j][] += min(dp[i][j-][],dp[i-][j][] + fxia);

 #include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <string>
#include <cstring>
#include <vector> #define N 105
#define ll long long
#define inf 0x3fffffff using namespace std; int n,m;
int dp[N][N][]; //0xia,1you
char s[N][N]; int checkxia(int x,int y)
{
if(x == n) return ;
if(s[x+][y] == 'b') return ;
else return ;
} int checkyou(int x,int y)
{
if(y == m) return ;
if(s[x][y+] == 'b') return ;
else return ;
} int main()
{
//freopen("in.txt","r",stdin);
int i,j,k;
int fxia,fyou;
while(scanf("%d%d",&n,&m)!=EOF)
{
for(i=;i<=n+;i++){
for(j=;j<=m+;j++){
for(k=;k<=;k++){
dp[i][j][k]=inf;
}
}
}
for(i = ;i <= n ;i++){
scanf("%s",s[i]+);
}
for(i = ;i <= n;i++){
for(j = ;j <= m;j++){
fxia = checkxia(i,j);
fyou = checkyou(i,j);
for(k = ;k <= ;k++){
dp[i][j][k] = ;
if(s[i][j] == 'b'){
dp[i][j][k] = ;
}
}
if(i == && j== ){
dp[i][j][] = dp[i][j][] + fyou;
continue;
}
dp[i][j][] += min(dp[i-][j][],dp[i][j-][] + fyou);
dp[i][j][] += min(dp[i][j-][],dp[i-][j][] + fxia);
}
}
/*
for(i = 1;i <= n;i++){
for(j = 1;j <= m;j++){ for(k = 0 ;k <= 1;k++){
printf(" i =%d j=%d k=%d dp=%d\n",i,j,k,dp[i][j][k]);
} }
}*/
printf("%d\n",min(dp[n][m][],dp[n][m][]));
}
return ;
}

hihocoder #1290 : Demo Day的更多相关文章

  1. hihocoder #1290 : Demo Day (2016微软编程测试第三题)

    #1290 : Demo Day 时间限制:10000ms 单点时限:1000ms 内存限制:256MB 描述 You work as an intern at a robotics startup. ...

  2. ACM学习历程—Hihocoder 1290 Demo Day(动态规划)

    http://hihocoder.com/problemset/problem/1290 这题是这次微软笔试的第三题,过的人比第一题少一点,这题一眼看过去就是动态规划,不过转移方程貌似不是很简单,调试 ...

  3. 【hihocoder】Demo Day

    时间限制:10000ms 单点时限:1000ms 内存限制:256MB 描述 You work as an intern at a robotics startup. Today is your co ...

  4. hihoCoder Demo Day dp

    题意:有一个机器人被困在一个的迷宫中,机器人的初始位置是,目的地是,并且它的移动方式很奇怪:只能一直向右,直到不能再向右才能把方向变成向下:只能一直向下,直到不能再向下才能把方向变成向右.迷宫中的每个 ...

  5. BZOJ1695 : [Usaco2007 Demo]Walk the Talk

    观察单词表可以发现: 对于长度为3的单词,前两个字母相同的单词不超过7个 对于长度为4的单词,前两个字母相同的单词不超过35个 于是首先$O(26*26*nm)$预处理出 s1[x][i][j]表示( ...

  6. Echarts图表常用功能配置,Demo示例

    先看下效果图: 就如上图所示,都是些常用的基本配置. Legend分页,X轴设置,Y轴设置,底部缩放条设置, 数值显示样式设置,工具箱设置,自定义工具按钮, 绑定点击事件等等.这些配置代码中都做了简单 ...

  7. Mysql错误积累001-load data导入文件数据出现1290错误

    错误出现情景 在cmd中使用mysql命令,学生信息表添加数据.使用load data方式简单批量导入数据. 准备好文本数据: xueshengxinxi.txt 文件  数据之间以tab键进行分割 ...

  8. 通过一个demo了解Redux

    TodoList小demo 效果展示 项目地址 (单向)数据流 数据流是我们的行为与响应的抽象:使用数据流能帮我们明确了行为对应的响应,这和react的状态可预测的思想是不谋而合的. 常见的数据流框架 ...

  9. 很多人很想知道怎么扫一扫二维码就能打开网站,就能添加联系人,就能链接wifi,今天说下这些格式,明天做个demo

    有些功能部分手机不能使用,网站,通讯录,wifi基本上每个手机都可以使用. 在看之前你可以扫一扫下面几个二维码先看看效果: 1.二维码生成 网址 (URL) 包含网址的 二维码生成 是大家平时最常接触 ...

随机推荐

  1. UVALive 4080 Warfare And Logistics (最短路树)

    很多的边会被删掉,需要排除一些干扰进行优化. 和UVA - 1279 Asteroid Rangers类似,本题最关键的地方在于,对于一个单源的最短路径来说,如果最短路树上的边没有改变的话,那么最短路 ...

  2. Bellman-Ford与SPFA

    一.Bellman-Ford Bellman-Ford 算法是一种用于计算带权有向图中单源最短路径(当然也可以是无向图).与Dijkstra相比的优点是,也适合存在负权的图. 若存在最短路(不含负环时 ...

  3. Dijkstra算法——单源最短路算法

    一.介绍 迪杰斯特拉(Dijkstra)算法是典型最短路径算法,用于计算一个节点到其他各个节点的最短路径. 它的主要特点是以起始点为中心向外层层扩展(广度优先搜索思想),直到扩展到终点为止. 适用于有 ...

  4. mac上使用命令行显示隐藏文件

    终端中输入命令 打开<终端> - 粘贴下面的两行命令执行 defaults write com.apple.finder AppleShowAllFiles TRUEkillall Fin ...

  5. input提示文字;placeholder字体修改

    在很多网站上我们都看到input输入框显示提示文字,让我们一起来看看如果在input输入框中显示提示文字.我们只需要在<input>标签里添加:placeholder="提示文字 ...

  6. GloVe:另一种Word Embedding方法

    若想深层地理解GloVe和本文,最好了解SVD, word2vec(skip-gram为主)的相关知识.若仅寻求一种新的word embedding方法,可以不必了解以上前置知识. 一言以蔽之,Glo ...

  7. ABAQUS用户子程序一览表

    说明 ABAQUS用户子程序一览表 ABAQUSStandard subroutines Refence 说明 本系列文章本人基本没有原创贡献,都是在学习过程中找到的相关书籍和教程相关内容的汇总和梳理 ...

  8. Taro:使用taro完成小程序开发

    前言:taro是一个可以很好实现一次开发,多端统一的框架,本文只介绍它小程序端开发的一些内容.小程序项目搭建gitup已经有很清楚的说明:https://github.com/NervJS/taro ...

  9. vuex其实超简单,只需3步

    前言 之前几个项目中,都多多少少碰到一些组件之间需要通信的地方,而因为种种原因,event bus 的成本反而比vuex还高, 所以技术选型上选用了 vuex, 但是不知道为什么,团队里的一些新人一听 ...

  10. python爬虫基础07-selenium大全1/8-安装和简单使用

    Selenium笔记(1)安装和简单使用 本文集链接:https://www.jianshu.com/nb/25338984 简介 Selenium是一个用于Web应用程序测试的工具. Seleniu ...