Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 12409 Accepted Submission(s): 4541
Code:
一直WA, WA ,WA
原理是用了优先队列而不是普通的队列
这个原来用过
只是用了friend bool operator< ()
点这里右面链接: 传送门
#include
#include
#include
using namespace std;
typedef struct point
{
int x,y;
int step;
friend bool operator< (point a,point b)//这里这里这里
{
return a.step>b.step;//>号表示出队的是优先级低的,<号表示出队优先级高的
}
}point;
char a[211][211];
int vis[211][211];
int n,m,dir[4][2]={1,0,-1,0,0,1,0,-1};
point angel;
int r_x,r_y;
int bfs(point p)
{
int i;priority_queueq;
q.push(angel);
vis[angel.x][angel.y] = 1;
point head,temp ;
while(!q.empty())
{
head = q.top(); //出队一个并对这个进行搜索
q.pop();
if(head.x==r_x&&head.y==r_y) return head.step;//加上自己
for(i=0;i<4;i++)
{
temp.x = head.x + dir[i][0];//temp赋值
temp.y = head.y + dir[i][1];
if(temp.x<0 || temp.x>=n || temp.y<0 || temp.y>=m) continue;//越界
if(!vis[temp.x][temp.y] && a[temp.x][temp.y] != '#')
{
if(a[temp.x][temp.y]=='x') temp.step = head.step + 2;//直接把到这一个地方的时间加上
else temp.step = head.step + 1;
vis[temp.x][temp.y] = 1;
q.push(temp); //判断过后再入队
}
}
}
return -1;
}
int main()
{
int i,j,t;
while(scanf("%d%d",&n,&m)!=EOF)
{
for(i=0;i