【HDOJ】3345 War Chess
简单BFS。注意最后一组数据,每个初始点不考虑周围是否有敌人。
/* 3345 */
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <queue>
using namespace std; #define MAXN 105
#define INF 0xfffff typedef struct node_t {
int x, y, e;
node_t() {}
node_t(int xx, int yy, int ee) {
x = xx; y = yy; e = ee;
}
} node_t; char map[MAXN][MAXN];
bool stop[MAXN][MAXN];
int hp[MAXN][MAXN];
int hurt[MAXN][MAXN];
int n, m, mv;
int bx, by;
int dir[][] = {
-,,,-,,,,
}; void init() {
int i, j, k; memset(stop, false, sizeof(stop));
memset(hurt, -, sizeof(hurt));
for (i=; i<=n; ++i) {
for (j=; j<=m; ++j) {
if (map[i][j] == 'E') {
stop[i-][j] = stop[i][j-] = stop[i+][j] = stop[i][j+] = true;
hurt[i][j] = INF;
} else if (map[i][j] == 'Y') {
bx = i;
by = j;
} else if (map[i][j] == '.') {
hurt[i][j] = ;
} else if (map[i][j] == 'T') {
hurt[i][j] = ;
} else if (map[i][j] == 'R') {
hurt[i][j] = ;
} else if (map[i][j] == 'P') {
hurt[i][j] = ;
} else if (map[i][j] == '#') {
hurt[i][j] = INF;
}
}
}
} bool check(int x, int y) {
return x<= || x>n || y<= || y>m;
} void bfs() {
int x, y, e;
int i, j, k;
queue<node_t> Q;
node_t nd; memset(hp, -, sizeof(hp));
//if (stop[bx][by] == false)
Q.push(node_t(bx,by,mv));
hp[bx][by] = mv; while (!Q.empty()) {
nd = Q.front();
Q.pop(); for (i=; i<; ++i) {
x = nd.x + dir[i][];
y = nd.y + dir[i][];
if (check(x, y))
continue;
e = nd.e - hurt[x][y];
if (e > hp[x][y]) {
hp[x][y] = e;
if (stop[x][y] == false)
Q.push(node_t(x, y, e));
}
}
}
} void merge() {
int i, j, k; for (i=; i<=n; ++i) {
for (j=; j<=m; ++j) {
if (hp[i][j]>= && map[i][j]!='P') {
map[i][j] = '*';
}
}
}
map[bx][by] = 'Y';
} int main() {
int t;
int i, j, k; #ifndef ONLINE_JUDGE
freopen("data.in", "r", stdin);
freopen("data.out", "w", stdout);
#endif scanf("%d", &t);
while (t--) {
scanf("%d %d %d", &n, &m, &mv);
for (i=; i<=n; ++i)
scanf("%s", map[i]+);
init();
bfs();
merge();
for (i=; i<=n; ++i)
printf("%s\n", map[i]+);
printf("\n");
} return ;
}
【HDOJ】3345 War Chess的更多相关文章
- 【贪心】【Uva11729】 Commando War
你有n个部下,每个部下需要完成一项任务.第i个部下需要你花Bi分钟交待任务,然后他会立刻独立地.无间断地执行Ji分钟后完成任务.你需要选择交待任务的顺序,使得所有任务尽早执行完毕(即最后一个执行完的任 ...
- hdu 3345 War Chess
War Chess Time Limit : 2000/1000ms (Java/Other) Memory Limit : 32768/32768K (Java/Other) Total Sub ...
- HDU - 3345 War Chess 广搜+优先队列
War chess is hh's favorite game: In this game, there is an N * M battle map, and every player has hi ...
- 【HDOJ】【4405】Aeroplane chess飞行棋
概率DP/数学期望 kuangbin总结中的第4题 啊还是求期望嘛……(话说Aeroplane chess这个翻译怎么有种chinglish的赶脚……) 好像有点感觉了…… 首先不考虑直飞的情况: f ...
- 【HDOJ】2809 God of War
状态DP. /* 2809 */ #include <iostream> #include <queue> #include <cstdio> #include & ...
- 【HDOJ】4729 An Easy Problem for Elfness
其实是求树上的路径间的数据第K大的题目.果断主席树 + LCA.初始流量是这条路径上的最小值.若a<=b,显然直接为s->t建立pipe可以使流量最优:否则,对[0, 10**4]二分得到 ...
- 【HDOJ】【2829】Lawrence
DP/四边形不等式 做过POJ 1739 邮局那道题后就很容易写出动规方程: dp[i][j]=min{dp[i-1][k]+w[k+1][j]}(表示前 j 个点分成 i 块的最小代价) $w(l, ...
- 【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[ ...
随机推荐
- Qt 学习之路 :Qt Quick Controls
自 QML 第一次发布已经过去一年多的时间,但在企业应用领域,QML 一直没有能够占据一定地位.很大一部分原因是,QML 缺少一些在企业应用中亟需的组件,比如按钮.菜单等.虽然移动领域,这些组件已经变 ...
- URAL 1062 - Triathlon(半平面交)
这个题乍眼一看好像很简单,然后我就认为u.v.w只要有全部比另外一个人小的就不能win,否则就能win,但是这个思路只对了一半 不能win的结论是正确的,但是win的结论不止排除这一个条件 将这个人与 ...
- Google代码实验室
https://code.google.com/p/google-styleguide/
- Customizing the Test Runner
There are several situations where you want to customize Robolectric's test runner to perform some o ...
- HTML select 操作
今天遇到一个问题,就是想设置select的默认选择项.但是试了很多方法都不行: <fieldset data-role="contractstatus"> <la ...
- asp.net 事件模型
asp.net的原始设计构想,就是要让开发人员能够像 VB 开发工具那样,可以使用事件驱动式程序开发模式 (Event-Driven Programming Model) 的方法来开发网页与应用程序, ...
- hadoop集群环境搭建准备工作
一定要注意hadoop和linux系统的位数一定要相同,就是说如果hadoop是32位的,linux系统也一定要安装32位的. 准备工作: 1 首先在VMware中建立6台虚拟机(配置默认即可).这是 ...
- GitHub Desktop安装异常解决
为了更好的共同学习,共同进步,哥们推荐我使用GitHub记录自己每天的学习记录,当下很火的提供一个分布式的版本控制系统(Git)服务的网站,GitHub提供GitHub Desktop桌面程序方便协同 ...
- IE兼容问题
1.IE下event事件没有target属性,只有srcElement属性,解决方法:使用srcObj = event.srcElement ? event.srcElement : event.ta ...
- CentOS 5.4下的Memcache安装步骤(Linux+Nginx+PHP+Memcached)
原文链接:http://www.jb51.net/article/29668.htm