bfs()。题目的数据乱码。应该如下:

*****#*********
*.......$...*
*..***.......*
*....*****..*
*....******37A
*****......*
*.....******..*
***CA********** *****
*$**
*.**
***#* --
 #include <iostream>
#include <queue>
#include <cstring>
#include <cstdio>
#include <algorithm>
using namespace std; #define isUpper(ch) (ch>='A' && ch<='Z')
#define isLower(ch) (ch>='a' && ch<='z')
#define isDigit(ch) (ch>='0' && ch<='9')
#define INF 0x7f7f7f7f
#define MAXN 105 typedef struct node_t {
int x, y, z, t;
node_t() {}
node_t(int xx,int yy, int zz, int tt) {
x = xx; y = yy; z = zz; t = tt;
}
friend bool operator < (const node_t a, const node_t b) {
return a.t > b.t;
}
} node_t; int visit[MAXN][MAXN][];
char map[MAXN][MAXN];
int m, n;
int dir[][] = {-,,,,,-,,}; bool check(int x, int y) {
return x<||x>=m||y<||y>=n;
} int bfs() {
int x, y, z, t;
int i, j;
priority_queue<node_t> Q; memset(visit, 0x7f, sizeof(visit));
for (i=; i<m; ++i) {
for (j=; j<n; ++j) {
if (map[i][j]=='#') {
Q.push(node_t(i, j, , ));
visit[i][j][] = ;
} else if (isUpper(map[i][j])) {
Q.push(node_t(i, j, map[i][j]-'A'+, ));
visit[i][j][map[i][j]-'A'+] = ;
}
}
} while (!Q.empty()) {
node_t nd = Q.top(); if (map[nd.x][nd.y] == '$')
return nd.t; Q.pop();
for (i=; i<; ++i) {
x = nd.x + dir[i][];
y = nd.y + dir[i][];
if (check(x, y) || map[x][y]=='*')
continue;
if (map[x][y] == '.') {
if (nd.t < visit[x][y][nd.z]) {
visit[x][y][nd.z] = nd.t;
Q.push(node_t(x, y, nd.z, nd.t));
}
} else if (map[x][y] == '$') {
Q.push(node_t(x, y, nd.z, nd.t));
} else if (isDigit(map[x][y])) {
if (nd.z > && nd.t < visit[x][y][nd.z-]) {
visit[x][y][nd.z-] = nd.t;
Q.push(node_t(x, y, nd.z-, nd.t));
}
t = nd.t+map[x][y]-'';
if (t < visit[x][y][nd.z]) {
visit[x][y][nd.z] = t;
Q.push(node_t(x, y, nd.z, t));
}
}
}
} return -;
} int main() {
#ifndef ONLINE_JUDGE
freopen("data.in", "r", stdin);
#endif int i = , tmp; while (gets(map[i++]) != NULL) {
if (map[][] == '-')
break;
while (gets(map[i])!=NULL && strlen(map[i])!=)
++i;
m = i;
n = strlen(map[]);
tmp = bfs();
if (tmp == -)
printf("IMPOSSIBLE\n");
else
printf("%d\n", tmp);
i = ;
} return ;
}

【HDOJ】2416 Treasure of the Chimp Island的更多相关文章

  1. Treasure of the Chimp Island

    Treasure of the Chimp Island Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Jav ...

  2. 快速切题 hdu2416 Treasure of the Chimp Island 搜索 解题报告

    Treasure of the Chimp Island Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K ( ...

  3. 【HDOJ】5446 Unknown Treasure

    1. 题目描述题目很简单,就是求$C(n,m) % M$. 2. 基本思路这是一道应用了众多初等数论定理的题目,因为数据范围较大因此使用Lucas求$C(n,m) % P$.而M较大,因此通过$a[i ...

  4. 【HDOJ】1448 The Treasure

    这就是个简单的bfs.真没什么好说的,三维的状态就可以了.每次预处理一下monster的位置,然后再恢复. /* 1924 */ #include <iostream> #include ...

  5. 【HDOJ】4729 An Easy Problem for Elfness

    其实是求树上的路径间的数据第K大的题目.果断主席树 + LCA.初始流量是这条路径上的最小值.若a<=b,显然直接为s->t建立pipe可以使流量最优:否则,对[0, 10**4]二分得到 ...

  6. 【HDOJ】【3506】Monkey Party

    DP/四边形不等式 裸题环形石子合并…… 拆环为链即可 //HDOJ 3506 #include<cmath> #include<vector> #include<cst ...

  7. 【HDOJ】【3516】Tree Construction

    DP/四边形不等式 这题跟石子合并有点像…… dp[i][j]为将第 i 个点开始的 j 个点合并的最小代价. 易知有 dp[i][j]=min{dp[i][j] , dp[i][k-i+1]+dp[ ...

  8. 【HDOJ】【3480】Division

    DP/四边形不等式 要求将一个可重集S分成M个子集,求子集的极差的平方和最小是多少…… 首先我们先将这N个数排序,容易想到每个自己都对应着这个有序数组中的一段……而不会是互相穿插着= =因为交换一下明 ...

  9. 【HDOJ】【2829】Lawrence

    DP/四边形不等式 做过POJ 1739 邮局那道题后就很容易写出动规方程: dp[i][j]=min{dp[i-1][k]+w[k+1][j]}(表示前 j 个点分成 i 块的最小代价) $w(l, ...

随机推荐

  1. JQuery中_Radio、DropDownList、Checkbox选择控件的处理

    Radio  1.获取选中值,三种方法都可以: $('input:radio:checked').val(): $("input[type='radio']:checked").v ...

  2. hdu 4123 树形DP+RMQ

    http://acm.hdu.edu.cn/showproblem.php? pid=4123 Problem Description Bob wants to hold a race to enco ...

  3. TeleMCU视频会议之Android版本号WebRTC client支持

    本文原创自 http://blog.csdn.net/voipmaker  转载注明出处. 最新版本号TeleMCU 添加了Android手机端WebRTC视频会议能力,Android手机安装Chro ...

  4. HDOJ 1787 GCD Again(欧拉函数)

    GCD Again Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total ...

  5. 从今天开始学习C#啦

    此博客为证,在下从今天开始学习C#,并把心得体会记录下来.

  6. 纯css+js水平时间轴

    自定义,并自动加载时间节点 当前时间节点居中,突出显示 时间动态无痕添加 效果图: 初始状态 时间左走到一定2016.1月后 html: <!-- 水平时间轴 --> <div id ...

  7. My.Ioc 代码示例——使用条件绑定和元数据(可选)构建插件树

    本文旨在通过创建一棵插件树来演示条件绑定和元数据的用法. 说“插件树”也许不大妥当,因为在一般观念中,谈到插件树,我们很容易会想到 Winform/Wpf 中的菜单.举例来说,如果要在 Winform ...

  8. Asp.net中的页面跳转及post数据

    /// <summary> /// This method prepares an Html form which holds all data /// in hidden field i ...

  9. .Net程序员关于微信公众平台测试账户配置 项目总结

    今天项目第一次验收,夜晚吃过晚饭后,想把项目中用到的关于微信配置总结一下,虽然网上关于这方面的资料很多很多,还有官方API,但是总感觉缺点什么,就像期初做这个项目时,各方面找了很久的资料,说说配置吧! ...

  10. 跳转到QQ聊天界面和QQ群界面

    // uin=2977046873为QQ号 NSString *urlString = @"mqq://im/chat?chat_type=wpa&uin=2977046873&am ...