poj 3501 Escape from Enemy Territory 二分+bfs

2014-11-24 03:33:22 · 作者: · 浏览: 0

水题,不解释。

#include
  
   
#include
   
     #include
    
      #include
     
       #include
      
        using namespace std; #define N 1000002 struct node { int x,y; int dis; }base[10005],st,end; int n,m; int maps[1005][1005]; bool vis[1005][1005]; int dx[]={0,0,-1,1}; int dy[]={-1,1,0,0}; struct que { struct node t[N]; int head,tail; void init() { head = tail = 0; } bool empty() { return head == tail; } struct node top() { return t[head]; } void push(struct node a) { t[tail] = a; tail ++; if(tail >= N) tail -= N; } void pop() { head ++; if(head >= N) head -= N; } }q; int maxn; int leng; bool isok(int x,int y) { return x>=0&&x
       
        =0&&y
        
         =lim&&!vis[tt.x][tt.y]) { vis[tt.x][tt.y]=true; if(tt.x==end.x&&tt.y==end.y) { leng=tt.dis; return true; } q.push(tt); } } q.pop(); } return false; } int main() { int cas; scanf("%d",&cas); st.dis=0; int tt; while(cas--) { q.init(); maxn=0; scanf("%d%d%d",&tt,&n,&m); scanf("%d%d%d%d",&st.x,&st.y,&end.x,&end.y); for(int i=0;i