Problem - 2312

  一条很暴力,有点恶心的搜索。题意其实很简单,主要是pfs的时候拓展结点会有种麻烦的感觉。注意的是,这里的n和m跟平常见到的有所不同,交换过来了。我的代码就是在因为这个长宽的问题wa了一次。

代码如下:

 #include <cstdio>
#include <iostream>
#include <algorithm>
#include <cstring>
#include <queue>
#include <cctype> using namespace std; typedef pair<int, int> PII;
typedef pair<PII, PII> PPP;
typedef pair<int, PPP> PPPI; #define FI first
#define SE second
#define PRIQ priority_queue const int R = ;
const int C = ;
char mat[R][C];
bool vis[R][C][R][C];
int n, m; inline int dis(int a, int b, int c, int d) { return abs(a - c) + abs(b - d);}
inline bool inmat(int a, int b) { return <= a && a < n && <= b && b < m;} int work() {
PRIQ<PPPI> Q;
int nx, ny, cx, cy;
memset(vis, , sizeof(vis));
while (!Q.empty()) Q.pop();
for (int i = ; i < n; i++) {
for (int j = ; j < m; j++) {
if (mat[i][j] != 'S') continue;
for (int dx = -; dx <= ; dx++) {
nx = i + dx;
for (int dy = ; dy <= ; dy++) {
ny = j + dy;
if (inmat(nx, ny) && dis(i, j, nx, ny) <= && mat[nx][ny] != 'X' && !vis[i][j][nx][ny]) {
if (isdigit(mat[nx][ny])) Q.push(PPPI((int) '' - mat[nx][ny], PPP(PII(i, j), PII(nx, ny))));
else Q.push(PPPI(, PPP(PII(i, j), PII(nx, ny))));
vis[i][j][nx][ny] = true;
// cout << i << ' ' << j << ' ' << nx << ' ' << ny << endl;
}
ny = j - dy;
if (inmat(nx, ny) && dis(nx, ny, i, j) <= && mat[nx][ny] != 'X' && !vis[nx][ny][i][j]) {
if (isdigit(mat[nx][ny])) Q.push(PPPI((int) '' - mat[nx][ny], PPP(PII(nx, ny), PII(i, j))));
else Q.push(PPPI(, PPP(PII(nx, ny), PII(i, j))));
vis[nx][ny][i][j] = true;
// cout << nx << ' ' << ny << ' ' << i << ' ' << j << endl;
}
}
}
}
}
// cout << "find S" << endl;
while (!Q.empty()) {
PPPI cur = Q.top();
Q.pop();
int v = cur.FI, a = cur.SE.FI.FI, b = cur.SE.FI.SE, c = cur.SE.SE.FI, d = cur.SE.SE.SE;
// cout << v << ' ' << a << ' ' << b << ' ' << c << ' ' << d << endl;
if (mat[a][b] == 'T' || mat[c][d] == 'T') return -v;
for (int dx = -; dx <= ; dx++) {
nx = a + dx;
cx = c + dx;
for (int dy = ; dy <= ; dy++) {
ny = b + dy;
if (inmat(nx, ny) && dis(a, b, nx, ny) <= && mat[nx][ny] != 'X' && !vis[a][b][nx][ny]) {
if (isdigit(mat[nx][ny])) Q.push(PPPI((int) '' - mat[nx][ny] + v, PPP(PII(a, b), PII(nx, ny))));
else Q.push(PPPI(v, PPP(PII(a, b), PII(nx, ny))));
vis[a][b][nx][ny] = true;
// cout << nx << ' ' << ny << endl;
}
cy = d - dy;
if (inmat(cx, cy) && dis(cx, cy, c, d) <= && mat[cx][cy] != 'X' && !vis[cx][cy][c][d]) {
if (isdigit(mat[cx][cy])) Q.push(PPPI((int) '' - mat[cx][cy] + v, PPP(PII(cx, cy), PII(c, d))));
else Q.push(PPPI(v, PPP(PII(cx, cy), PII(c, d))));
vis[cx][cy][c][d] = true;
// cout << cx << ' ' << cy << endl;
}
}
}
}
return -;
} int main() {
// freopen("in", "r", stdin);
// freopen("out", "w", stdout);
while (cin >> m >> n && (n || m)) {
char buf[];
for (int i = ; i < n; i++) for (int j = ; j < m; j++) cin >> buf, mat[i][j] = buf[];
cout << work() << endl;
}
return ;
}

——written by Lyon

hdu 2312 Cliff Climbing (pfs)的更多相关文章

  1. 【hdu 4315】Climbing the Hill

    Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total Submission(s) ...

  2. HDU 4315:Climbing the Hill(阶梯博弈)

    http://acm.hdu.edu.cn/showproblem.php?pid=4315 题意:有n个人要往坐标为0的地方移动,他们分别有一个位置a[i],其中最靠近0的第k个人是king,移动的 ...

  3. 【转载】图论 500题——主要为hdu/poj/zoj

    转自——http://blog.csdn.net/qwe20060514/article/details/8112550 =============================以下是最小生成树+并 ...

  4. hdu图论题目分类

    =============================以下是最小生成树+并查集====================================== [HDU] 1213 How Many ...

  5. HDU图论题单

    =============================以下是最小生成树+并查集====================================== [HDU] 1213 How Many ...

  6. 【转】最短路&差分约束题集

    转自:http://blog.csdn.net/shahdza/article/details/7779273 最短路 [HDU] 1548 A strange lift基础最短路(或bfs)★254 ...

  7. 转载 - 最短路&差分约束题集

    出处:http://blog.csdn.net/shahdza/article/details/7779273 最短路 [HDU] 1548    A strange lift基础最短路(或bfs)★ ...

  8. 最短路&查分约束

    [HDU] 1548 A strange lift 根蒂根基最短路(或bfs)★ 2544 最短路 根蒂根基最短路★ 3790 最短路径题目 根蒂根基最短路★ 2066 一小我的观光 根蒂根基最短路( ...

  9. 【HDOJ图论题集】【转】

    =============================以下是最小生成树+并查集====================================== [HDU] How Many Table ...

随机推荐

  1. 获得浏览器User-agent的方法

    在浏览器的地址栏输入(不是全部都能用) javascript:alert(navigator.userAgent); 或者网页中 alert(navigator.userAgent) 或者后台中 St ...

  2. UE4物理模块(二)---建立物体碰撞

    在前文中介绍了什么是物理以及如何在UE4和PhysX中进行可视化调试: Jerry:UE4物理模块(一)---概述与可视化调试​zhuanlan.zhihu.com 这里调试只谈到了碰撞盒(后续还会有 ...

  3. 【CS Round #44 (Div. 2 only) A】Frequent Numbers

    [链接]h在这里写链接 [题意] 在这里写题意 [题解] 大水题 [错的次数] 0 [反思] 在这了写反思 [代码] /* */ #include <cstdio> #include &l ...

  4. 【风马一族_SQL Server】

    原文来自:http://www.cnblogs.com/sows/p/6097684.html (博客园的)风马一族 侵犯版本,后果自负 2016-11-24  14:25:45 命令行方式处理服务管 ...

  5. spark-ML基础

    一.ML组件 ML的标准API使用管道(pipeline)这样的方式,可以将多个算法或者数据处理过程整合到一个管道或者一个流程里运行,其中包含下面几个部分: 1. dataFrame:用于ML的dat ...

  6. 廖雪峰Python总结2

    1.切片 L[0:3]表示,从索引0开始,直到索引3为止,但是不包括索引3.如果第一个索引是0,还可以省略L[:3] 倒数切片:L[-n:-1],-1是倒数第一个元素,L[-n:-1]不包括倒数第一个 ...

  7. Hdu 4497

    题目链接 已知 gcd(x, y, z) = G, lcm(x, y, z) = L, 求有多少种组合(x, y, z)可以满足条件.G, L都在32位int范围内. 思路: 素数分解 + 容斥 L ...

  8. Introduction to 3D Game Programming with DirectX 12 学习笔记之 --- 第十八章:立方体贴图

    原文:Introduction to 3D Game Programming with DirectX 12 学习笔记之 --- 第十八章:立方体贴图 代码工程地址: https://github.c ...

  9. LeetCode153 Find Minimum in Rotated Sorted Array. LeetCode162 Find Peak Element

    二分法相关 153. Find Minimum in Rotated Sorted Array Suppose a sorted array is rotated at some pivot unkn ...

  10. Servlet过虑器

    过滤器是在请求的预处理和后处理时调用的对象. 主要用于执行转换,日志记录,压缩,加解密,输入验证等过滤任务. servlet过滤器是可插拔的,即它在web.xml文件中定义,如果从web.xml文件中 ...