【HDOJ】2416 Treasure of the Chimp Island
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的更多相关文章
- Treasure of the Chimp Island
Treasure of the Chimp Island Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Jav ...
- 快速切题 hdu2416 Treasure of the Chimp Island 搜索 解题报告
Treasure of the Chimp Island Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K ( ...
- 【HDOJ】5446 Unknown Treasure
1. 题目描述题目很简单,就是求$C(n,m) % M$. 2. 基本思路这是一道应用了众多初等数论定理的题目,因为数据范围较大因此使用Lucas求$C(n,m) % P$.而M较大,因此通过$a[i ...
- 【HDOJ】1448 The Treasure
这就是个简单的bfs.真没什么好说的,三维的状态就可以了.每次预处理一下monster的位置,然后再恢复. /* 1924 */ #include <iostream> #include ...
- 【HDOJ】4729 An Easy Problem for Elfness
其实是求树上的路径间的数据第K大的题目.果断主席树 + LCA.初始流量是这条路径上的最小值.若a<=b,显然直接为s->t建立pipe可以使流量最优:否则,对[0, 10**4]二分得到 ...
- 【HDOJ】【3506】Monkey Party
DP/四边形不等式 裸题环形石子合并…… 拆环为链即可 //HDOJ 3506 #include<cmath> #include<vector> #include<cst ...
- 【HDOJ】【3516】Tree Construction
DP/四边形不等式 这题跟石子合并有点像…… dp[i][j]为将第 i 个点开始的 j 个点合并的最小代价. 易知有 dp[i][j]=min{dp[i][j] , dp[i][k-i+1]+dp[ ...
- 【HDOJ】【3480】Division
DP/四边形不等式 要求将一个可重集S分成M个子集,求子集的极差的平方和最小是多少…… 首先我们先将这N个数排序,容易想到每个自己都对应着这个有序数组中的一段……而不会是互相穿插着= =因为交换一下明 ...
- 【HDOJ】【2829】Lawrence
DP/四边形不等式 做过POJ 1739 邮局那道题后就很容易写出动规方程: dp[i][j]=min{dp[i-1][k]+w[k+1][j]}(表示前 j 个点分成 i 块的最小代价) $w(l, ...
随机推荐
- TCP 连接的要点
概念 TIME_WAIT: socket 仍然有数据在内核中待发送直到发送成功或超时,此socket不能被内核删除,同时等待是否要重传Ack对端还已发过来的FIN Linger Time:socket ...
- [转] STL源码学习----lower_bound和upper_bound算法
http://www.cnblogs.com/cobbliu/archive/2012/05/21/2512249.html PS: lower_bound of value 就是最后一个 < ...
- Java笔试题二:读程序
public class SopResult { public static void main(String[] args) { int i = 4; System.out.println(&quo ...
- .NET通信中的同步和异步处理
同步与异步的概念: .NET中的通信数据处理有同步和异步之分,我理解的同步过程是接收端接收数据,如果数据没有过来,就一直等着(阻塞过程),直到有数据传送过来可以接收,接下来程序才继续向下进行:异步过程 ...
- Unicode 与多字节编码
int _tmain(int argc, _TCHAR* argv[]) { //定义LPWSTR 类型的宽字符串 LPWSTR szUnicode = L"This is a Unicod ...
- 简单html以及css的用法
我将利用三天的时间来完成制作京东首页的静态页面效果,其中包含的内容有html以及css. 1.在开发进行之前,首先要配置开发环境:我们需要安装sublime webstorm vscode Hb ...
- ASP.NET5中间件
小的应用组件可以包含到Http请求管道当中,ASP.NET5 集成了中间件,被包在了应用程序的Configure方法当中. 1. 什么是中间件 中间件是一组被装到应用程序管道的请求和响应中的组件.每一 ...
- Ext.grid.Panel表格分页
转载:http://www.cnblogs.com/libingql/archive/2012/04/22/2464994.html cshtml @{ Layout = null; } <!D ...
- 计时器(Chronometer)的使用
安卓提供了一个计时器组件:Chronometer,该组件extends TextView,因此都会显示一段文本,但是它显示的时间是从某个起始时间开始过去了多少时间,它只提供了android:forma ...
- STL中的set容器
#include <iostream> #include <set> using namespace std; int main() { set<int> s; s ...