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. android圆角View实现及不同版本这间的兼容

    在做我们自己的APP的时候,为了让APP看起来更加的好看,我们就需要将我们的自己的View做成圆角的,毕竟主流也是将很多东西做成圆角,和苹果的外观看起来差不多,看起来也还不错. 要将一个View做成圆 ...

  2. C++高精度运算类bign (重载操作符)

    大数据操作,有例如以下问题: 计算:456789135612326542132123+14875231656511323132 456789135612326542132123*14875231656 ...

  3. [转] 【开源访谈】Muduo 作者陈硕访谈实录

    关于开源访谈 开源访谈是开源中国推出的一系列针对国内优秀开源软件作者的访谈,以文字的方式记录并传播.我们希望开源访谈能全面的展现国内开源软件.开源软件作者的现状,着实推动国内开源软件的应用与发展. [ ...

  4. 码表 ASCII Unicode GBK UTF-8

    2017-1-3 [ASCII]一个字节(7位,128个字符,2个16进制) 不包含中文 ASCII(American Standard Code for Information Interchang ...

  5. 使用EF 的简单的增删改查

    using DAL; using Model; using System; using System.Collections.Generic; using System.Linq; using Sys ...

  6. new Date()在IE,谷歌,火狐上的一些注意项

    1.new Date()在IE浏览器上IE9以上的可以直接使用new Date("yyyy-MM-dd"),但是在IE8上的时候就要使用new Date("yyyy/MM ...

  7. jquery/js当前URL对当前栏目高亮突出显示

    html: 1 <div class="nav"> 2 <ul> 3 <li><a href="index.html" ...

  8. git 的记住用户名和密码和一些常用

    git config --global core.autocrlf falsegit config --global color.ui truegit config --global credenti ...

  9. 谷歌插件postman如果不能用,就用git命令发送post请求

     curl -X POST --data '{"name":"zfpx"}' -H 'Content-Type:application/json' http:/ ...

  10. servlet+jdbc+javabean其实跟ssh差不多

    我给的这个架构可以代替ssh的架构进行项目的开发 common中放的是一些公用类 dao中放的是一些对数据的处理 entity其实也就是javabean service中放的是一些抽象类,简单来说抽象 ...