Title: Portal
Test instructions very simple does not explain, water problem together.
#include <iostream>#include<string.h>#include<stdio.h>#include<algorithm>typedef __int64 LL;#defineINF 0x3f3f3f3f#include<math.h>#include<queue>using namespacestd;structnode{intX,y,ans; BOOL operator< (ConstNode &a)Const//Small to large sort { returnAns>A.ans; }};node st,ff;intn,m,p,s,t,s,e,s2,e2,v[ A][ A];Chara[ A][ A];intfx[]= {1,-1,0,0};intfy[]= {0,0,1,-1};intMain () {intsum,k=0; while(SCANF ("%d%d", &n,&m)! =EOF) {Priority_queue<node>Q; while(!q.empty ()) Q.pop (); Sum=-1; scanf ("%d%d%d",&p,&s,&T); for(intI=0; i<n; i++) scanf ("%s", A[i]); scanf ("%d%d%d%d",&s,&e,&s2,&E2); memset (V,0,sizeof(v)); St.x=s,st.y=e,st.ans=0; V[s][e]=1; Q.push (ST); while(!Q.empty ()) {FF=Q.top (); Q.pop (); if(ff.x==s2&&ff.y==E2) {Sum=Ff.ans; Break; } for(intI=0; i<4; i++) {St.x=ff.x+Fx[i]; St.y=ff.y+Fy[i]; if(v[st.x][st.y]==0&&a[st.x][st.y]!='@') { if(a[st.x][st.y]=='T') {St.ans=ff.ans+T; V[ST.X][ST.Y]=1; Q.push (ST); } Else if(a[st.x][st.y]=='.') {St.ans=ff.ans+R; V[ST.X][ST.Y]=1; Q.push (ST); } Else if(a[st.x][st.y]=='#') {St.ans=ff.ans+Q; V[ST.X][ST.Y]=1; Q.push (ST); } }}} printf ("Case %d:%d\n",++k,sum); } return 0;}
Hdu2425:hiking Trip (simple BFS, priority queue implementation)