2015 多校赛 第四场 1009 (hdu 5335)
An explorer gets lost in this grid. His position now is (1,1), and he wants to go to the exit. Since to arrive at the exit is easy for him, he wants to do something more difficult. At first, he'll write down the number on position (1,1). Every time, he could make a move to one adjacent position (two positions are adjacent if and only if they share an edge). While walking, he will write down the number on the position he's on to the end of his number. When finished, he will get a binary number. Please determine the minimum value of this number in binary system.
For each testcase, the first line contains two integers n and m (1≤n,m≤1000). The i-th line of the next n lines contains one 01 string of length m, which represents i-th row of the maze.
题意:给出一幅图,起点在左上角终点在左下角。沿途走过的数字连起来为最后所得的二进制数,设法令该数最小,输出之。
思路:
起点为1的情况,令二进制数长度最小,则每次只往右走或往下走,并且步数相同时走 0 优先。
起点为0的情况,则按着 0 搜到离终点最近的为 1 的点,再按上述的方式走即可。
广搜题,,但 T 到跪。看了标程打了一份。这种 bfs 方式第一次见,确实6,我还是太年轻。。
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<string>
using namespace std;
char g[][];
int n,m,t,head,tail;
#define maxn 1000005
int vis[][],x[maxn],y[maxn];
int dx[]={,-,,},dy[]={,,,-};
string bfs(){
memset(vis,,sizeof(vis));
vis[head=][tail=]=;
x[head]=,y[head++]=;
while(head!=tail){
if(g[x[tail]][y[tail]]==''){
for(int i=;i<;i++){
int X=x[tail]+dx[i],Y=y[tail]+dy[i];
if(X>=&&X<n&&Y>=&&Y<m&&!vis[X][Y]){
x[head]=X,y[head++]=Y;
vis[X][Y]=;
}
}
}
tail++;
}
if(vis[n-][m-]&&g[n-][m-]=='') return "";
int sum=;
string ans="";
for(int i=;i<n;i++){
for(int j=;j<m;j++)
if(vis[i][j]) sum=max(sum,i+j);
}
for(int k=sum;k<n+m-;k++){
char c='';
for(int i=,j=k-i;i<n;i++,j--) if(j>=&&j<m&&vis[i][j]){
if(i+<n) c=min(c,g[i+][j]);
if(j+<m) c=min(c,g[i][j+]);
}
ans+=c;
for(int i=,j=k-i;i<n;i++,j--) if(j>=&&j<m&&vis[i][j]){
if(i+<n&&g[i+][j]==c) vis[i+][j]=;
if(j+<m&&g[i][j+]==c) vis[i][j+]=;
}
}
return ans;
}
int main(){
//freopen("in.txt","r",stdin);
scanf("%d",&t);
while(t--){
scanf("%d%d",&n,&m);
for(int i=;i<n;i++)
scanf("%s",g[i]);
cout<<bfs()<<endl;
}
return ;
}
2015 多校赛 第四场 1009 (hdu 5335)的更多相关文章
- 2015 多校赛 第四场 1010 (hdu 5336)
Problem Description XYZ is playing an interesting game called "drops". It is played on a r ...
- 2015 多校赛 第五场 1010 (hdu 5352)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5352 看题看得心好累. 题目大意: 给出 n 个点,依次执行 m 次操作:输入“1 x”时,表示将与 ...
- 2015 多校赛 第七场 1011 (hdu 5379)
题意:给定一棵树,树上有 n 个节点.问有多少种方案,使得在每个节点上依次放置数 1~n 后,每个节点的儿子节点上的数连续(比如 1 为根,有1-2,1-3,1-4,则令2,3,4上的数连续),每个子 ...
- 2015 多校赛 第五场 1006 (hdu 5348)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5348 题目大意:给出一幅无向图,问是否存在一种方案,使得给每条边赋予方向后,每个点的入度与出度之差小于 ...
- 2015 多校赛 第三场 1002 (hdu 5317)
Description Mr. Hdu is interested in Greatest Common Divisor (GCD). He wants to find more and more i ...
- hdu 5328 Problem Killer(杭电多校赛第四场)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5328 题目大意:找到连续的最长的等差数列or等比数列. 解题思路:1.等差等比的性质有很多.其中比较重 ...
- 【杂题总汇】HDU多校赛第十场 Videos
[HDU2018多校赛第十场]Videos 最后一场比赛也结束了…… +HDU传送门+ ◇ 题目 <简要翻译> 有n个人以及m部电影,每个人都有一个快乐值.每场电影都有它的开始.结束时间和 ...
- NOI.AC NOIP模拟赛 第四场 补记
NOI.AC NOIP模拟赛 第四场 补记 子图 题目大意: 一张\(n(n\le5\times10^5)\)个点,\(m(m\le5\times10^5)\)条边的无向图.删去第\(i\)条边需要\ ...
- hdu5379||2015多校联合第7场1011 树形统计
pid=5379">http://acm.hdu.edu.cn/showproblem.php? pid=5379 Problem Description Little sun is ...
随机推荐
- centos添加永久的环境变量
cd /etc/profile.d/ 创建一个sh文件 vi dotnetpath.sh 内容如下: export PATH=$PATH:/opt/dotnet 保存,重启,这就有了一个永久的环境变量
- scss基础
1.变量$ 全局 局部 .div{ $color:yellow; } 2.类似函数@mixin border-radius($radius) { }引用:@include border-radius( ...
- css 样式 解释
字体属性:(font) 大小 {font-size: x-large;}(特大) xx-small;(极小) 一般中文用不到,只要用数值就可以,单位:PX.PD 样式 {font-style: obl ...
- 18清明校内测试T3
扫雷(mine) Time Limit:1000ms Memory Limit:128MB 题目描述 rsy最近沉迷于一款叫扫雷的游戏. 这个游戏是这样的.一开始网格上有n*m个位置,其中有一些位 ...
- Flask - 请求处理流程和上下文源码分析
目录 Flask - 请求处理流程和上下文 WSGI Flask的上下文对象及源码解析 0. 请求入口 1.请求上下文对象的创建 2. 将请求上下文和应用上下文入栈 3.根据请求的URl执行响应的视图 ...
- Modbus 协议解析
- 【Codeforces 466C】Number of Ways
[链接] 我是链接,点我呀:) [题意] 让你把数组分成3个连续的部分 每个部分的和要一样 问你有多少种分法 [题解] 先处理出来num[i] 表示i..n这里面有多少个j 满足aft[j] = af ...
- 2.1.5、SparkEnv中创建MapOutputTracker
SparkEnv中创建MapOutputTracker def registerOrLookupEndpoint( name: String, endpointCreator: => RpcEn ...
- 从零搭建流媒体服务器+obs推流直播
背景介绍 本文使用的流媒体服务器的搭建是基于rtmp(Real Time Message Protocol)协议的,rtmp协议是应用层的协议,要依靠底层的传输层协议,比如tcp协议来保证信息传输的可 ...
- git 拉取远程分支 --本地分支不存在
git checkout -b 本地分支名 origin/远程分支名