http://acm.hdu.edu.cn/showproblem.php?pid=3442

题意:ABCD有各自的攻击力与攻击范围,刘备只能走"C"与".",问刘备从"s" 走到"!"受到的最小攻击力。ps(受过一次攻击的下次将不会再对刘备造成伤害)

思路:用优先队列,每次搜索攻击力最小的,并对当前的状态标记。。。

#include <stdio.h>
#include <iostream>
#include <string.h>
#include <queue>
#include <stdlib.h>
using namespace std;
const int N=;
char Map[N][N];
int a[N][N][],vis[N][N][];
int dir[][] = {{,-},{,},{-,},{,}};
int n,m,sx,sy,ex,ey;
struct node
{
int x,y,hp,state;
friend bool operator < (node a,node b)
{
return b.hp < a.hp;//在这跪了n遍。。要想优先队列里的值从小到大排列,则比较函数应该从大到小排
}
};
bool in(int x,int y)
{
if (x >= &&x <= n&&y >= &&y <= m)
return true;
return false;
}
bool judge(int x1,int y1,int x2,int y2,int c)
{
if(abs(x1-x2)+abs(y1-y2) <= c)
return true;
return false;
} void deal(int x,int y,char ch)
{
if (ch=='A')
{
for (int i = x-; i <= x+; i++)
{
for (int j = y-; j <= y+; j++)
{
if(in(i,j)&&judge(x,y,i,j,))
a[i][j][] = ;
}
}
}
else if (ch=='B')
{
for (int i = x-; i <= x+; i++)
{
for (int j = y-; j <= y+; j++)
{
if (in(i,j)&&judge(x,y,i,j,))
a[i][j][] = ;
}
}
}
else if (ch=='C')
a[x][y][] = ;
else if (ch=='D')
{
for (int i = x-; i <= x+; i++)
{
for (int j = y-; j <= y+; j++)
{
if (in(i,j)&&judge(x,y,i,j,))
a[i][j][] = ;
}
}
}
else if (ch=='E')
{
for (int i = x-; i <= x+; i ++)
{
for (int j = y-; j <= y+; j ++)
{
if (in(i,j)&&judge(x,y,i,j,))
a[i][j][] = ;
}
}
}
}
int bfs()
{
priority_queue<node>q;
while(!q.empty()) q.pop();
q.push((struct node)
{
sx,sy,,
});
vis[sx][sy][] = ;
while(!q.empty())
{
node temp,t = q.top();
q.pop();
printf("%d %d %d\n",t.x,t.y,t.hp);
if (t.x==ex&&t.y==ey)
return t.hp;
for (int i = ; i < ; i++)
{
temp.x = t.x+dir[i][];
temp.y = t.y+dir[i][];
temp.hp = t.hp;
temp.state = t.state;
if (in(temp.x,temp.y)&&(Map[temp.x][temp.y]=='C'||Map[temp.x][temp.y]=='$'||Map[temp.x][temp.y]=='.'||Map[temp.x][temp.y]=='!'))
{
for (int k = ; k < ; k++)
{
if((temp.state&(<<k))==&&a[temp.x][temp.y][k])
{
temp.hp+=a[temp.x][temp.y][k];
temp.state+=(<<k);
}
}
if (!vis[temp.x][temp.y][temp.state])
{
vis[temp.x][temp.y][temp.state] = ;
q.push(temp);
}
}
}
}
return -;
}
int main()
{
int t,o = ;
cin>>t;
while((t--))
{
o++;
cin>>n>>m;
memset(a,,sizeof(a));
memset(vis,,sizeof(vis));
for (int i = ; i <= n; i++)
{
for (int j = ; j <= m; j++)
{
cin>>Map[i][j];
if (Map[i][j]=='A'||Map[i][j]=='B'||Map[i][j]=='C'||Map[i][j]=='D'||Map[i][j]=='E')
deal(i,j,Map[i][j]);
if (Map[i][j]=='$')
{
sx = i;
sy = j;
}
if (Map[i][j]=='!')
{
ex = i;
ey = j;
}
}
}
int ans = bfs();
printf("Case %d: %d\n",o,ans);
}
return ;
}

最新文章

  1. TestNG 入门教程
  2. HDU 1754 I Hate It (线段树)
  3. ios cocos2d TexturePacker生成文件后的使用方法
  4. JDK安装 配置环境变量
  5. load-on-startup
  6. Using zend-navigation in your Album Module
  7. ios 动画效果CATransition笔记
  8. java 获取本机ip及mac地址
  9. 【ThinkingInC++】61、非成员运算符
  10. android adb 不同的方式使用特定的解释
  11. 日期的本质是double
  12. Java:函数,类,数组之间的运用
  13. 带着新人简单看看servlet到springmvc
  14. 新萌渗透测试入门DVWA 教程2:DWVA 的配置和暴力破解靶机
  15. OpenStack Q版本新功能以及各核心组件功能对比
  16. mv 命令
  17. es6笔记(3) 变量的解构赋值
  18. Linux用户及用户组管理命令
  19. js 中的console.log有什么作用
  20. MySQL8.0初体验

热门文章

  1. Plan &amp; Future
  2. 「 CODE[VS] P2853 」 方格游戏
  3. 【Python实践-8】和为S的两个数字
  4. java nio--采用Selector实现Socket通信
  5. Windows学习总结(9)——Windows系统常用的网络控制指令
  6. 转载 - Python里面关于 模块 和 包 和 __init__.py 的一些事
  7. [COGS309] [USACO 3.2] 香甜的黄油
  8. WinForm 中限制只能输入数字
  9. MVC和MVVM的区别
  10. HTTP状态码图示