hdu 5652 bestcoder 77 div2 2
来源:互联网 发布:韩国美女直播秀软件 编辑:程序博客网 时间:2024/05/02 02:38
http://bestcoder.hdu.edu.cn/contests/contest_chineseproblem.php?cid=682&pid=1003
思路:
二分最先 A 不能到达B 的值 ,判断A 是否能到达B 广搜 标记 就可了
#include<bits/stdc++.h>using namespace std;const int maxn = 505;char a[maxn][maxn];char b[maxn][maxn];int vis[maxn][maxn];int dri[4][2] = {{0,1},{0,-1},{-1,0},{1,0} };struct node{ int x,y ;} c[maxn*maxn];int n,m;bool bfs(){ memset(vis,0,sizeof(vis)); queue<node>q; node s; for(int j= 0; j<m; j++) { if(b[0][j]=='0') { s.x= 0; s.y =j; q.push(s); } } while(!q.empty()) { node now = q.front(); q.pop(); if(now.x==n-1) return true; for(int i = 0; i<4; i++) { node next ; next.x = now.x+dri[i][0]; next.y = now.y +dri[i][1]; if(vis[next.x][next.y]==0&&next.x>=0&&next.y>=0&&next.x<n&&next.y<m&&b[next.x][next.y]=='0') { q.push(next); vis[next.x][next.y] =1; } } } return false ;}bool slove(int x){ memset(b,0,sizeof(b)); for(int i = 0; i<n; i++) for(int j =0; j<m; j++) { b[i][j] = a[i][j]; } for(int i = 1; i<=x; i++) { b[c[i].x][c[i].y] = '1'; } if(bfs())return true; return false;}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]); int q; cin>>q; for(int i = 1; i<=q; i++) scanf("%d%d",&c[i].x,&c[i].y); int l = 1; int r = q; while(l<=r) { int mid = (l+r)>>1; if(slove(mid)) { l = mid+1; } else r = mid-1; } if(l==q){puts("-1");continue;} printf("%d\n",l); } return 0;}
0 0
- hdu 5652 bestcoder 77 div2 2
- BestCoder Round #77 (div2) B
- BestCoder Round #77 (div2) C
- HDU 5560 5561 5562 5563 (Bestcoder#77 div2 A B C D)
- Bestcoder Div2 #77 A So easy
- HDU 5655 5656 ,Bestcoder #78 div2 A B
- bestcoder #11div2
- bestcoder #50 div2
- Bestcoder #54 div2
- Bestcoder Round#69 div2
- bestcoder round 71 div2
- Bestcoder Round 72# div2
- BestCoder #74 B (div2)
- bestcoder #79 div2 A
- hdu_5671_Matrix(BestCoder Round #81 (div2))
- hdu_5672_Strings BestCoder Round #81 (div2)
- BestCoder #1-2 HDU 4858
- BestCoder Round #60 div2 A B C HDU 5504 5505 5506
- leetcode 11.Container With Most Water
- mac下用cornerstone,在update时提示the working copy is locked
- ntpd使用
- Linux入门:VIM
- 动态规划之寻找两个字符串最长公共子串
- hdu 5652 bestcoder 77 div2 2
- Android 6.0 运行时权限处理
- 贪心1008
- Hibernate 集合属性的操作
- spark HA
- hibernate 数据库 方言配置在哪个jar包的什么位置?
- 将HashMap,HashSet写入文本的工具类
- 自动异机(异地)备份
- word中实现章节标题的自动编号