题意:
给一个图..起点是'Y'..目标点是'C'...'*'是道路.过路费是cost...P是虫洞..可以不需要代价的瞬移...'#'是墙不能走过...问从起点到终点的最小代价...
题解:
由于只给了r*c<=5000...开个一维的也行..对于(x,y).....在一维里的位置为y*c+x....然后就暴力BFS..找出解~
Program:
#include<iostream>
#include<stdio.h>
#include<string.h>
#include<cmath>
#include<queue>
#include<stack>
#include<set>
#include<time.h>
#include<map>
#include<algorithm>
#define ll long long
#define eps 1e-5
#define oo 10007
#define pi acos(-1.0)
#define MAXN 5005
using namespace std;
struct node
{
int x,y;
}P[505];
char s[MAXN],T[MAXN];
int C[MAXN];
bool inqueue[MAXN];
queue<node> myqueue;
int main()
{
int r,c,i,x,k,num,cost;
while (~scanf("%d%d%d",&r,&c,&cost))
{
memset(C,0x3f,sizeof(C));
node h,temp;
num=0;
for (i=0;i<r;i++)
{
scanf("%s",s);
for (x=0;x<c;x++)
{
T[i*c+x]=s[x];
if (s[x]=='Y') h.y=i,h.x=x,C[i*c+x]=0;
if (s[x]=='P') P[++num].y=i,P[num].x=x;
}
}
while (!myqueue.empty()) myqueue.pop();
memset(inqueue,false,sizeof(inqueue));
myqueue.push(h);
while (!myqueue.empty())
{
h=myqueue.front();
myqueue.pop();
if (T[h.y*c+h.x]=='C') break;
inqueue[h.y*c+h.x]=false;
if (T[h.y*c+h.x]=='P')
for (i=1;i<=num;i++)
if (C[P[i].y*c+P[i].x]>C[h.y*c+h.x])
{
C[P[i].y*c+P[i].x]=C[h.y*c+h.x];
if (!inqueue[P[i].y*c+P[i].x])
{
temp.y=P[i].y,temp.x=P[i].x;
myqueue.push(temp);
inqueue[P[i].y*c+P[i].x]=true;
}
}
if (h.x>0 && T[h.y*c+h.x-1]!='#')
{
if (T[h.y*c+h.x-1]=='*') k=cost; else k=0;
if (C[h.y*c+h.x-1]>C[h.y*c+h.x]+k)
{
C[h.y*c+h.x-1]=C[h.y*c+h.x]+k;
if (!inqueue[h.y*c+h.x-1])
{
temp.x=h.x-1,temp.y=h.y;
myqueue.push(temp);
inqueue[h.y*c+h.x-1]=true;
}
}
}
if (h.y>0 && T[(h.y-1)*c+h.x]!='#')
{
if (T[(h.y-1)*c+h.x]=='*') k=cost; else k=0;
if (C[(h.y-1)*c+h.x]>C[h.y*c+h.x]+k)
{
C[(h.y-1)*c+h.x]=C[h.y*c+h.x]+k;
if (!inqueue[(h.y-1)*c+h.x])
{
temp.x=h.x,temp.y=h.y-1;
myqueue.push(temp);
inqueue[(h.y-1)*c+h.x]=true;
}
}
}
if (h.x!=c-1 && T[h.y*c+h.x+1]!='#')
{
if (T[h.y*c+h.x+1]=='*') k=cost; else k=0;
if (C[h.y*c+h.x+1]>C[h.y*c+h.x]+k)
{
C[h.y*c+h.x+1]=C[h.y*c+h.x]+k;
if (!inqueue[h.y*c+h.x+1])
{
temp.x=h.x+1,temp.y=h.y;
myqueue.push(temp);
inqueue[h.y*c+h.x+1]=true;
}
}
}
if (h.y!=r-1 && T[(h.y+1)*c+h.x]!='#')
{
if (T[(h.y+1)*c+h.x]=='*') k=cost; else k=0;
if (C[(h.y+1)*c+h.x]>C[h.y*c+h.x]+k)
{
C[(h.y+1)*c+h.x]=C[h.y*c+h.x]+k;
if (!inqueue[(h.y+1)*c+h.x])
{
temp.x=h.x,temp.y=h.y+1;
myqueue.push(temp);
inqueue[(h.y+1)*c+h.x]=true;
}
}
}
}
if (T[h.y*c+h.x]!='C') printf("Damn teoy!\n");
else printf("%d\n",C[h.y*c+h.x]);
}
return 0;
}