FZU 2150 求双搜最优解
来源:互联网 发布:淘宝一分钱刷信誉 编辑:程序博客网 时间:2024/06/05 09:27
http://acm.fzu.edu.cn/problem.php?pid=2150
#include<stdio.h>#include<iostream>#include<math.h>#include<stdlib.h>#include<ctype.h>#include<algorithm>#include<vector>#include<string.h>#include<queue>#include<stack>#include<set>#include<map>#include<sstream>#include<time.h>#include<utility>#include<malloc.h>using namespace std;int t, n, m;char b[15][15];int dir[4][2] = { { -1, 0 }, { 1, 0 }, { 0, 1 }, { 0, -1 } };int vis[15][15];int check(int x, int y){if (x >= 0 && x < n && y >= 0 && y < m)return 1;return 0;}struct node{int x;int y;int t;}q[150];queue<node> de;int step = 0;int main(){scanf("%d",&t);int c = 1;while (t--){scanf("%d%d", &n, &m);for (int i = 0; i < n; i++)scanf("%s",b[i]);int num = 0;for (int i = 0; i < n; i++)for (int j = 0; j < m; j++){if (b[i][j] == '#'){q[num].x = i;q[num++].y = j;}}int ans = 0x3f3f3f3f;if (num == 2)ans = 0;else for (int i = 0; i < num; i++){for (int j = i; j < num; j++){int sx = q[i].x;int sy = q[i].y;int ex = q[j].x;int ey = q[j].y;{while (!de.empty()) de.pop();node qq, qqq;qq.x = sx; qq.y = sy; qq.t = 0;qqq.x = ex; qqq.y = ey; qqq.t = 0;de.push(qq);de.push(qqq);memset(vis,0,sizeof(vis));vis[sx][sy] = vis[ex][ey] = 1;step = 0;/////////////////while (!de.empty()){node qq = de.front();de.pop();step = qq.t;for (int i = 0; i < 4; i++){int x = qq.x + dir[i][0];int y = qq.y + dir[i][1];if (!check(x, y) || vis[x][y] || b[x][y] == '.')continue;node qqq;qqq.x = x;qqq.y = y;qqq.t = qq.t + 1;vis[x][y] = 1;de.push(qqq);}}////////////////int ok = 1;for (int i = 0; i < n; i++){for (int j = 0; j < m; j++){if (vis[i][j] == 0 && b[i][j] == '#'){ok = 0;break;}}}if (ok){ans = min(ans, step);}}}}if (ans == 0x3f3f3f3f)ans = -1;printf("Case %d: %d\n",c++,ans);}}
0 0
- FZU 2150 求双搜最优解
- FZU 2150
- FZU 2150
- FZU 2150 Fire Game
- FZU 2150 Fire Game
- FZU 2150 Fire Game
- FZU 2150 Fire Game
- FZU 2150 Fire Game
- FZU-2150 Fire Game
- fzu 2150 Fire Game
- FZU 2150 Fire Game
- FZU 2150 - Fire Game
- fzu 2150 Fire Game
- FZU 2150 Fire Game
- FZU 2150 Fire Game
- FZU 2150Fire Game
- FZU 2150 Fire Game
- FZU 2150 BFS
- windows7如何打开远程桌面
- CAD中如何查看要素高程
- CAD文件格式(.dxf)的等高线在Arc…
- poll()函数总结
- Effective C++学习笔记(Part Seven:Item 41-48)
- FZU 2150 求双搜最优解
- epoll()函数总结
- Table 行合并操作
- 键盘扫描码
- OpenGL帧缓存对象(FBO:Frame Buffer Object)
- select、poll、epoll之间的区别总结[整理]
- CustomPropertyDrawer-Change the height of Property field
- 在linux6上安装RAC时多路径的权限设置
- 会话EJB系列(四)SessionBean事务管理