杭州现场赛的题。BFS+DFS
#include#include #include #define inf 9999999using namespace std;char mp[105][105];int sq[5][5];int step[4][2]={ {0,1},{1,0},{0,-1},{-1,0}};struct pos{ int x,y;};int n,m,prn,x,y,tmp,ans,cnt;bool viss[5];int bfs(pos bg,pos ed){ int i; pos que[20000]; int front=0,rear=1; bool vis[105][105]={false}; vis[bg.x][bg.y]=true; que[0]=bg; int cnt[20000]={0}; if(ed.x==bg.x&&ed.y==bg.y) return 0; while(rear>front) { for(i=0;i<4;i++) { if(que[front].x+step[i][0]>=0&&que[front].x+step[i][0] =0&&que[front].y+step[i][1] >n>>m&&(n+m)) { memset(sq,0,sizeof(sq)); memset(viss,false,sizeof(viss)); int i,j; ans=inf; tmp=0; cnt=0; pos st; for(i=0;i >mp[i][j]; if(mp[i][j]=='@') { st.x=i; st.y=j; } } } cin>>prn; pos pr[4]; for(i=0;i >pr[i].x>>pr[i].y; pr[i].x--; pr[i].y--;// cout< <<" "< <