hdu5335 多校联合第四场1009 搜索
来源:互联网 发布:直播间源码下载 编辑:程序博客网 时间:2024/06/05 16:17
http://acm.hdu.edu.cn/showproblem.php?pid=5335
Problem Description
In an n∗m maze, the right-bottom corner is the exit (position (n,m) is the exit). In every position of this maze, there is either a 0 or a 1 written on it.
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.
An explorer gets lost in this grid. His position now is
Input
The first line of the input is a single integer T (T=10) , indicating the number of testcases.
For each testcase, the first line contains two integersn 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.
For each testcase, the first line contains two integers
Output
For each testcase, print the answer in binary system. Please eliminate all the preceding 0 unless the answer itself is 0 (in this case, print 0 instead).
Sample Input
22 211113 3001111101
Sample Output
111101/** hdu5335 多校联合第四场1009 搜索 题目大意:给定一个由0和1组成的棋盘,从左上角走到右下角路径(上下左右四种行走方式)组成二进制数问最小的是什么 解题思路:(转)如果我们规定这个人只能向下走或者向右走的话,问题会变的简单,二进制长度为n-m+1,然后我们可以一步一步求它每一步走的情况。 首先他的二进制第一位一定要为0。在第一位为0之后一定只会向下或者向右走到终点,因为中间如果向上走或者向左走的话,二进制的 位数会增加,大小肯定增大,所以问题的关键是找出从原点一直走0的位置,中间经过的0的位置距离终点最短的点,在这之后便只能向 下走或者向右走。 */ #include <stdio.h>#include <string.h>#include <algorithm>#include <iostream>#include <queue>using namespace std;const int maxn=1003;int n,m,ans;bool flag[maxn][maxn];char a[maxn][maxn];int dx[][2]= {1,0,0,1,-1,0,0,-1};void bfs(){ queue <pair<int,int> >q; q.push(make_pair(0,0)); while(!q.empty()) { int x=q.front().first; int y=q.front().second; q.pop(); for(int i=0; i<4; i++) { int xx=x+dx[i][0]; int yy=y+dx[i][1]; if(flag[xx][yy]||xx<0||xx>=n||yy<0||yy>=m)continue; flag[xx][yy]=1; ans=max(xx+yy,ans); if(a[xx][yy]=='0') q.push(make_pair(xx,yy)); } }}int main(){ int T; scanf("%d",&T); while(T--) { scanf("%d%d",&n,&m); for(int i=0; i<n; i++) { scanf("%s",a[i]); } ans=0; memset(flag,0,sizeof(flag)); flag[0][0]=1; if(a[0][0]=='0')bfs(); if(ans==n+m-2) { printf("%c\n",a[n-1][m-1]); continue; } printf("1"); bool ok=0; for(int i=ans; i<n-1+m-1; i++) { bool judge=0; for(int k=0; k<=i; k++) { int x=k; int y=i-k; if(x<0||x>=n||y<0||y>=m||flag[x][y]==0)continue; if(ok&&a[x][y]=='1')continue; for(int j=0; j<2; j++) { int xx=x+dx[j][0]; int yy=y+dx[j][1]; if(xx<0||xx>=n||yy<0||yy>=m)continue; flag[xx][yy]=1; if(a[xx][yy]=='0')judge=1; } } ok=judge; if(judge)printf("0"); else printf("1"); } printf("\n"); } return 0;}
0 0
- hdu5335 多校联合第四场1009 搜索
- [bfs+贪心] 多校第四场 HDU5335 Walk Out
- 2013多校联合训练第四场
- HDOJ多校联合第四场
- 2016多校联合第四场 HDU5768
- HDU/HDOJ 3875 Euclidean Algorithm 多校联合第四场
- hdu 4642 fliping game 多校联合训练第四场
- hdu 4639 hehe 多校联合训练第四场
- [模拟] 多校联合第四场 HDU5327 Olympad
- [枚举] 多校联合第四场 hdu328 problem killer
- hdu5334 Virtual Participation 多校联合第四场
- 2015多校联合第四场hdu5327Olympiad 递推
- HDU 6069 Counting Divisors 多校联合第四场
- [搜索]hdu5335
- F-SLIKAR 多校联合第七场 搜索问题
- 多校联合第三场
- 2013暑期多校联合训练\第四场\Problem H Hehe
- hdu 4632 Palindrome subsequence 区间dp 多校联合训练第四场
- JQuery判断radio单选框是否选中
- Codeforces Round #287 (Div. 2) C. Guess Your Way Out! 二叉树遍历
- 测试一个config server 服务器挂机后,集群是否能读写数据
- C、C++、C#、Java、php、python语言的内在特性及区别
- xcode使用svn
- hdu5335 多校联合第四场1009 搜索
- Android自定义文字闪烁渐变色的跑马灯
- 如何配置Bean
- Navigation 简单自动寻路
- PropertyPlaceholderConfigurer的使用
- request.getScheme()的使用方法
- SOA平台架构解析
- iOS UItableView通讯录
- MySQL一些常用的时间函数 current_timestamp()