标签:ui5 dap VRM gpo yml nbsp awr ssi splay
沙雕题
BFS找联通块即可,但是会超时,考虑用spfa,两个队列交替扩展即可
#include <iostream> #include <cstdio> using namespace std; const int N=4e3+10; struct Point { int x,y; }d[4],q[2][N*N]; int h,w,ans; int b[N][N]; bool vis[N][N]; char c[N][N]; inline bool Check(Point a) { return a.x>0&&a.x<h+1&&a.y>0&&a.y<w+1&&!vis[a.x][a.y]&&c[a.x][a.y]!=‘.‘; } inline void BFS() { register bool wch=0; int sum=0,cnt=0,h[2]={1,1},t[2]={0,0}; q[0][++t[0]]=(Point){1,1};b[1][1]=1;vis[1][1]=1; while (h[wch]<=t[wch]) { while (h[wch]<=t[wch]) { register Point u=q[wch][h[wch]];h[wch]++; for (register int i=0;i<4;i++) if (Check((Point){u.x+d[i].x,u.y+d[i].y})) { register Point v=(Point){u.x+d[i].x,u.y+d[i].y}; register bool w=c[u.x][u.y]!=c[v.x][v.y]; ans=max(ans,b[v.x][v.y]=b[u.x][u.y]+w); q[wch^w][++t[wch^w]]=v; vis[v.x][v.y]=1; } } wch^=1; } } int main() { d[0]=(Point){0,1};d[1]=(Point){1,0};d[2]=(Point){0,-1};d[3]=(Point){-1,0}; scanf("%d%d",&h,&w); for (register int i=1;i<=h;i++) scanf("%s",c[i]+1); BFS(); printf("%d",ans); }
标签:ui5 dap VRM gpo yml nbsp awr ssi splay
原文地址:https://www.cnblogs.com/mastervan/p/11155103.html