HDU 3533 Escape bfs 难度:1

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

一道普通的bfs,但是由于代码实现出了bug还是拖了很久甚至对拍了

需要注意的是:

1.人不能经过炮台

2.能量耗尽时如果进入终点且终点没有炮弹也可以

3.炮台会遮挡住别的炮弹

前两点认为读题时不能确定

#include 
#include 
#include 
#include 

using namespace std;

const int maxn=102,maxm=102,maxk=102;
const int inf=0x3fffffff;
const char badmess[20]={"Bad luck!"};
const int dx[4]={-1,1,0,0},dy[4]={0,0,-1,1};

struct castle{
    int d,t,v,x,y;
    castle(){d=t=v=x=y=-1;}
    castle(int _d,int _t,int _v,int _x,int _y){_d=d;_t=t;_v=v;_x=x;_y=y;}
}cas[maxk];
vectorrow[maxn],col[maxm];

struct man{
    int x,y,t;
    man(){x=y=t=-1;}
    man(int _x,int _y,int _t):x(_x),y(_y),t(_t){}
};

int charind[255];
char buff[3];
bool vis[maxn][maxm][maxk];
int m,n,k,d;

queueque;

bool in(int x,int y){return x>=0&&x<=n&&y>=0&&y<=m;}
bool ok(int x,int y,int t,int i){
    castle c=cas[i];
    if(c.v==0&&(c.x!=x||c.y!=y))return true;
    if(dx[c.d]!=0&&abs(c.x-x)%c.v==0){
        int tt=abs(c.x-x)/c.v;
        if(tt&&t>=tt&&(t-tt)%c.t==0)return false;//存在炮弹恰巧在该时间经过该点
        if(tt==0&&t%c.t==0)return false;//如果本来就在炮台上
    }
    if(dy[c.d]!=0&&abs(c.y-y)%c.v==0){
        int tt=abs(c.y-y)/c.v;
        if(tt&&t>=tt&&(t-tt)%c.t==0)return false;
        if(tt==0&&t%c.t==0)return false;
    }
    return true;
}
bool judge(int x,int y,int t){
    int sind=-1,nind=-1,wind=-1,eind=-1;
    for(int i=0;i<(int)col[y].size();i++){//找到四个方向上最近的,这些不会遮挡其他
        int c=col[y][i];
        if(cas[c].x>=x){
            if(nind==-1||cas[nind].x>cas[c].x){
                nind=c;
            }
        }
        if(cas[c].x<=x){
            if(sind==-1||cas[sind].x=y){
            if(wind==-1||cas[wind].y>cas[r].y){
                wind=r;
            }
        }
        if(cas[r].y<=y){
            if(eind==-1||cas[eind].y

 

转载于:https://www.cnblogs.com/xuesu/p/4372067.html

你可能感兴趣的:(HDU 3533 Escape bfs 难度:1)