qp
by 夢蝶 @ 2023-07-08 13:59:40
@[tong888](/user/1015190) 写qp干什么?
by LiJoQiao @ 2023-07-08 14:00:18
@[LiJoQiao](/user/945364)
第一个评论的
by 夢蝶 @ 2023-07-08 14:01:33
$INF$ 写小了,赋值 `0f3f3f3f3f` 就过了
```cpp
#include<bits/stdc++.h>
using namespace std;
int INF=0x3f3f3f3f;
int n,m,ma[1005][1005],dis[1005][1005];
int dx[12]={0,-1,0,1,-2,-1,1,2,-1,0,1,0},
dy[12]={2,1,1,1,0,0,0,0,-1,-1,-1,-2},
dv[12]={2,2,0,2,2,0,0,2,2,0,2,2};
struct node{
int x,y,c,v;
bool operator <(node b)const{
return v>b.v;
}
};
void bfs(){
priority_queue<node> q;
q.push(node({1,1,ma[1][1],dis[1][1]}));
node a,nex;
while(!q.empty()){
a=q.top();
q.pop();
if(dis[a.x][a.y]<a.v){
continue;
}
for(int i=0;i<12;i++){
nex.x=a.x+dx[i];
nex.y=a.y+dy[i];
nex.v=a.v+dv[i];
if(nex.x<=0||nex.y<=0||nex.x>n||nex.y>n){
continue;
}
nex.c=ma[nex.x][nex.y];
if(nex.c==0){
continue;
}
if(a.c!=nex.c){
nex.v=nex.v+1;
}
if(dis[nex.x][nex.y]>nex.v){
dis[nex.x][nex.y]=nex.v;
q.push(nex);
}
}
}
}
int main(){
memset(dis,0x3f,sizeof(dis));
dis[1][1]=0;
cin>>n>>m;
for(int i=1;i<=m;i++){
int x,y,c;
cin>>x>>y>>c;
ma[x][y]=c+1;
}
bfs();
if(ma[n][n]==0){
int ans=min(dis[n][n-1],dis[n-1][n])+2;
if(ans>=INF){
cout<<-1;
}else{
cout<<ans;
}
}else if(dis[n][n]>=INF){
cout<<-1;
}else{
cout<<dis[n][n];
}
return 0;
}
```
by LiJoQiao @ 2023-07-08 14:01:49
[评测记录](https://www.luogu.com.cn/record/114423381)
by LiJoQiao @ 2023-07-08 14:02:12
@[tong888](/user/1015190) 在求助帖下面写大可不必
by LiJoQiao @ 2023-07-08 14:02:29
@[LiJoQiao](/user/945364)
。。。。你对一个辣鸡说话大可不必
by 夢蝶 @ 2023-07-08 14:03:39
@[LiJoQiao](/user/945364) 3Q,已关
by caotianhao @ 2023-07-08 14:03:41