跳到正文

ygxdmss20121024

1785737

这个家伙不懒,什么都留下了

在洛谷打开
资料、奖项与版本

资料

编号
1785737
抓取

版本

  1. v2当前
  2. v1

https://www.luogu.com.cn/article/1y31k5tz

Gemini 3.0-Pro-Preview

#include<bits/stdc++.h> using namespace std; int n,m,k,xx[205],yy[205],l,r,djy[6]={1,1,0,-1,0,1},djx[6]={0,1,1,0,-1,-1},doy[6]={1,0,-1,-1,-1,0},dox[6]={0,1,1,0,-1,-1},flag; int d[205][205],ans,fx,fy; char z[205][205]; struct node{ int x,y,step; }q[40005]; int main(){ ios::sync_with_stdio(0); cin.tie(0),cout.tie(0); cin>>n>>m>>k; for(int i=1;i<=n;i++){ if(i%2==1) for(int j=1;j<=m;j++){ cin>>z[i][j]; } if(i%2==0) for(int j=1;j<=m+1;j++){ cin>>z[i][j]; } } for(int i=1;i<=k;i++){ cin>>xx[i]>>yy[i]; z[xx[i]][yy[i]]=’#’; } z[xx[1]][yy[1]]=’.’; for(int i=2;i<=k;i++){ flag=0; z[xx[i]][yy[i]]=‘e’; l=0,r=1; q[r]={xx[i-1],yy[i-1],0}; while(l<r){ l++; node now=q[l]; for(int j=0;j<=5;j++){ node temp=now; temp.step++; if(now.x%2==1){ temp.x+=djx[j]; temp.y+=djy[j]; } else{ temp.x+=dox[j]; temp.y+=doy[j]; } if(temp.x>n || temp.x<1 || (temp.y>m && now.x%2==1) || (temp.y>m+1 && now.x%2==0) || temp.y<1 || d[temp.x][temp.y]==1 || z[temp.x][temp.y]==’#’){ continue; } r++; q[r]=temp; // cout<<temp.x<<temp.y<<“\n”; if(z[temp.x][temp.y]==‘e’){ flag=1; break; } } if(flag==1){ break; } } if(flag==0){ cout<<-1; return 0; } else{ ans+=q[r].step; } } cout<<ans; return 0; }

还没有收录这位用户的文章。