标签:class namespace mem 这一 c++ set ott other arc
Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 65535/32768 K (Java/Others)
Total Submission(s): 255 Accepted Submission(s):
99
#include<bits/stdc++.h>
using namespace std;
int N,M,P;
int fx[4][2]={1,0,-1,0,0,1,0,-1};
bool vis[16][16][1<<11];
int pic[16][16][16][16];
bool key[16][16][16];
struct node
{
int x,y,w,hal;
};
int bfs(int hal)
{
memset(vis,0,sizeof(vis));
vis[1][1][hal]=1;
queue<node> Q;
Q.push(node{1,1,0,hal});
while(!Q.empty()){
node cur=Q.front(); Q.pop();
int x=cur.x,y=cur.y,w=cur.w;
for(int i=0;i<4;++i){hal=cur.hal;
int dx=x+fx[i][0];
int dy=y+fx[i][1];
if(dx<=0||dy<=0||dx>N||dy>M||pic[x][y][dx][dy]==0) continue;
int bor=(pic[x][y][dx][dy]==-1?0:pic[x][y][dx][dy]);
if(!((hal>>bor)&1)) continue;
for(int j=0;j<=10;++j){
if(key[dx][dy][j]) hal=(hal|(1<<j));
} if(vis[dx][dy][hal]) continue;
vis[dx][dy][hal]=1;
//cout<<dx<<" "<<dy<<" "<<w+1<<" "<<hal<<endl;
Q.push(node{dx,dy,w+1,hal});
if(dx==N&&dy==M) return w+1;
}
}
return -1;
}
int main()
{
int i,j,k,K,S;
int x1,x2,y1,y2;
while(cin>>N>>M>>P>>K){ memset(pic,-1,sizeof(pic));
memset(key,0,sizeof(key));
while(K--){
cin>>x1>>y1>>x2>>y2>>k;
pic[x1][y1][x2][y2]=pic[x2][y2][x1][y1]=k;
}cin>>S;
while(S--){int x,y,q;
cin>>x>>y>>q;
key[x][y][q]=1;
}
int hal=0;
for(i=1;i<=10;++i) {
if(key[1][1][i])
hal=(hal|(1<<i));
}
cout<<bfs(hal|1)<<endl;
}
return 0;
}
标签:class namespace mem 这一 c++ set ott other arc
原文地址:http://www.cnblogs.com/zzqc/p/6938494.html