标签:main namespace har 日记 its efi bit else include
思路:
spfa;
代码:
#include <bits/stdc++.h> using namespace std; #define INF 0x3f3f3f3f struct NodeType { int x,y,k; NodeType(int x_,int y_,int k_):x(x_),y(y_),k(k_){} NodeType(){} }; const int dx[5]={0,-1,0,1,0}; const int dy[5]={0,0,1,0,-1}; int n,m,d,r,dis[1005][1005][2]; char Map[1005][1005]; queue<NodeType>que; bool if_[1005][1005][2]; int main() { scanf("%d%d%d%d",&n,&m,&d,&r); for(int i=1;i<=n;i++) scanf("%s",Map[i]+1); for(int i=1;i<=n;i++) { for(int v=1;v<=m;v++) dis[i][v][0]=dis[i][v][1]=INF; } dis[1][1][0]=0;int x,y,k;que.push(NodeType(1,1,0)),if_[1][1][0]=true; NodeType now; for(;!que.empty();) { now=que.front(),que.pop(); if_[now.x][now.y][now.k]=false,k=now.k; for(int i=1;i<=4;i++) { x=now.x+dx[i],y=now.y+dy[i]; if(x>0&&x<=n&&y>0&&y<=m&&Map[x][y]==‘.‘) { if(dis[now.x][now.y][k]+1<dis[x][y][k]) { dis[x][y][k]=dis[now.x][now.y][k]+1; if(!if_[x][y][k]) if_[x][y][k]=true,que.push(NodeType(x,y,k)); } } } if(!k) { x=now.x+d,y=now.y+r; if(x>0&&x<=n&&y>0&&y<=m&&Map[x][y]==‘.‘) { dis[x][y][1]=dis[now.x][now.y][0]+1; if(!if_[x][y][1]) if_[x][y][1],que.push(NodeType(x,y,1)); } } } if(dis[n][m][0]==INF&&dis[n][m][1]==INF) printf("-1\n"); else printf("%d\n",min(dis[n][m][1],dis[n][m][0])); return 0; }
标签:main namespace har 日记 its efi bit else include
原文地址:http://www.cnblogs.com/IUUUUUUUskyyy/p/7103680.html