BZOJ 2464 中山市选 2009 小明的游戏 最短路
来源:互联网 发布:ftp安卓软件 编辑:程序博客网 时间:2024/05/01 07:47
题目大意:给出一个地图,如果经过两个不同的区块,需要花费1,否则不需要花费。问从st到ed最小需要花费多少。
思路:签到题。
CODE:
#include <queue>#include <cstdio>#include <cstring>#include <iostream>#include <algorithm>#define MAX 510#define MAXP 250010#define MAXE 2000010using namespace std;const int dx[] = {0,1,-1,0,0};const int dy[] = {0,0,0,1,-1};struct Status{int pos,len;Status(int _,int __):pos(_),len(__) {}bool operator <(const Status &a)const {return len > a.len;}};char src[MAX][MAX];int num[MAX][MAX];int head[MAXP],total;int next[MAXE],aim[MAXE],length[MAXE];int st,ed,m,n;int f[MAXP];inline void Initialize(){total = 0;memset(head,0,sizeof(head));}inline void Add(int x,int y,int len){next[++total] = head[x];aim[total] = y;length[total] = len;head[x] = total;}inline int SPFA(){static priority_queue<Status> q;while(!q.empty())q.pop();memset(f,0x3f,sizeof(f));q.push(Status(st,0));f[st] = 0;while(!q.empty()) {Status now = q.top(); q.pop();if(f[now.pos] < now.len)continue;int x = now.pos;for(int i = head[x]; i; i = next[i])if(f[aim[i]] > f[x] + length[i]) {f[aim[i]] = f[x] + length[i];q.push(Status(aim[i],f[aim[i]]));}}return f[ed];}int main(){while(scanf("%d%d",&m,&n),m + n) {Initialize();for(int i = 1; i <= m; ++i)scanf("%s",src[i] + 1);int cnt = 0;for(int i = 1; i <= m; ++i)for(int j = 1; j <= n; ++j)num[i][j] = ++cnt;int x,y;scanf("%d%d",&x,&y);x++,y++,st = num[x][y];scanf("%d%d",&x,&y);x++,y++,ed = num[x][y];for(int i = 1; i <= m; ++i)for(int j = 1; j <= n; ++j)for(int k = 1; k <= 4; ++k) {int fx = i + dx[k];int fy = j + dy[k];if(!fx * fy || fx > m || fy > n)continue;Add(num[i][j],num[fx][fy],src[fx][fy] != src[i][j]);}printf("%d\n",SPFA());}return 0;}
CODE:
0 0
- BZOJ 2464 中山市选 2009 小明的游戏 最短路
- bzoj 2464: 中山市选[2009]小明的游戏 最短路
- BZOJ 2464 中山市选2009 小明的游戏 SPFA
- BZOJ 2464: 中山市选[2009]小明的游戏
- BZOJ 2464 中山市选[2009]小明的游戏 SPFA
- BZOJ[2464]中山市选[2009]小明的游戏 SPFA
- bzoj 2464 中山市选[2009]小明的游戏
- 【BZOJ2464】【中山市选2009】小明的游戏 最短路水过
- BZOJ 2464: 中山市选[2009]小明的游戏 简单搜索
- 2464: 中山市选[2009]小明的游戏
- [BZOJ2464]中山市选[2009]小明的游戏
- 【中山市选2009】【BZOJ2464】小明的游戏
- 【bzoj2464】【中山市选2009】【小明的游戏】【spfa】
- BZOJ2464: 中山市选[2009]小明的游戏
- BZOJ 2438: [中山市选2011]杀人游戏
- bzoj[中山市选2009]谁能赢呢?
- BZOJ 2464 小明的游戏
- BZOJ 2438 [中山市选2011] 杀人游戏 (图的联通,tarjan)
- RealView MDK 使用
- 第十三周项目一(1) 数组大折腾(从前往后输出)
- NSSortDescriptor(数组排序)
- Android学习系列(29)--App调试的几个命令实践
- Java GC系列(3):垃圾回收器种类
- BZOJ 2464 中山市选 2009 小明的游戏 最短路
- 查看基于Android 系统单个进程内存、CPU使用情况的几种方法
- lockCanvas为NULL的原因
- Sencha Touch 2 实现跨域访问
- Unity3D镜头抖动特效
- PHP类与对象
- google MarkerClusterer v3
- vim下的ctags和taglist等的使用和配置
- mysql查询当前时间,一天内,一周,一个月内的sql语句