It is easy to find the largest room and the number of rooms in the original. Then, from bottom left to right, find the location of the demolition. Remove and then BFS once to find area.
#include <iostream>#include<cstdio>#include<cmath>#include<algorithm>#include<vector>#include<iomanip>#include<cstring>#include<map>#include<queue>#include<Set>#include<cassert>#include<stack>#defineMKP Make_pairusing namespacestd;Const Doubleeps=1e-8; typedefLong LongLon;ConstLon sz= -, inf=0x7FFFFFFF;intn,m,arr[sz][sz],dx[]={0,-1,0,1},dy[]={-1,0,1,0};BOOLVst[sz][sz];structnd{intx, y; nd (intAintb): X (a), Y (b) {}};voidinit () {cin>>m>>N; for(intI=1; i<=n;++i) { for(intj=1; j<=m;++j) cin>>Arr[i][j]; }}intBFsintBgxintbgy) { intres=1; Queue<nd>Q; Vst[bgx][bgy]=1; Q.push (ND (bgx,bgy)); for(;!Q.empty ();) {nd frt=Q.front (); Q.pop (); for(intI=0;i<4;++i) {intnx=frt.x+dx[i],ny=frt.y+Dy[i]; if(! (arr[frt.x][frt.y]& (1<<i)) &&nx>=1&&nx<=n&&ny>=1&&ny<=m&&!Vst[nx][ny]) {Vst[nx][ny]=1; Q.push (ND (nx,ny)); ++Res; } } } returnRes;}voidWorkint&block,int&MAXB) {Block=0; MAXB=0; for(intI=1; i<=n;++i) { for(intj=1; j<=m;++j) {if(!Vst[i][j]) {MAXB=Max (MAXB,BFS (i,j)); ++Block; } } }}voidWORK2 (int&MAXV,int&maxx,int&maxy,Char&Maxd) {MAXV=0; for(intj=1; j<=m;++j) { for(inti=n;i>=1;--i) {if(arr[i][j]&2) {memset (VST,0,sizeof(VST)); ARR[I][J]-=2; intCur=BFS (I,J); if(cur>MAXV) {MAXV=cur; Maxx=i,maxy=J; Maxd='N'; } Arr[i][j]+=2; } } for(inti=n;i>=1;--i) {if(arr[i][j]&4) {memset (VST,0,sizeof(VST)); ARR[I][J]-=4; intCur=BFS (I,J); if(cur>MAXV) {MAXV=cur; Maxx=i,maxy=J; Maxd='E'; } Arr[i][j]+=4; } } }}intMain () {Std::ios::sync_with_stdio (0); //freopen ("D:\\1.txt", "R", stdin);Lon Casenum; //cin>>casenum; //For (Lon Time=1;time<=casenum;++time){init (); intBLOCK,MAXB; Work (BLOCK,MAXB); cout<<block<<Endl; cout<<maxb<<Endl; intMaxv,maxx,maxy; CharMaxd; WORK2 (Maxv,maxx,maxy,maxd); cout<<maxv<<Endl; cout<<maxx<<" "<<maxy<<" "<<maxd<<Endl; } return 0;}
p1457 the Castle