标签:har names max -- tac tle pac cout queue
原图找最大的房间及房间数很容易。然后从左下到右上找拆的位置。拆掉再bfs一次找面积。
#include <iostream> #include <cstdio> #include <cmath> #include <algorithm> #include <vector> #include <iomanip> #include <cstring> #include <map> #include <queue> #include <set> #include <cassert> #include <stack> #define mkp make_pair using namespace std; const double EPS=1e-8; typedef long long lon; const lon SZ=60,INF=0x7FFFFFFF; int n,m,arr[SZ][SZ],dx[]={0,-1,0,1},dy[]={-1,0,1,0}; bool vst[SZ][SZ]; struct nd{ int x,y; nd(int a,int b):x(a),y(b){} }; void init() { cin>>m>>n; for(int i=1;i<=n;++i) { for(int j=1;j<=m;++j)cin>>arr[i][j]; } } int bfs(int bgx,int bgy) { int res=1; queue<nd> q; vst[bgx][bgy]=1; q.push(nd(bgx,bgy)); for(;!q.empty();) { nd frt=q.front(); q.pop(); for(int i=0;i<4;++i) { int nx=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; } } } return res; } void work(int &block,int &maxb) { block=0; maxb=0; for(int i=1;i<=n;++i) { for(int j=1;j<=m;++j) { if(!vst[i][j]) { maxb=max(maxb,bfs(i,j)); ++block; } } } } void work2(int &maxv,int &maxx,int &maxy,char &maxd) { maxv=0; for(int j=1;j<=m;++j) { for(int i=n;i>=1;--i) { if(arr[i][j]&2) { memset(vst,0,sizeof(vst)); arr[i][j]-=2; int cur=bfs(i,j); if(cur>maxv) { maxv=cur; maxx=i,maxy=j; maxd=‘N‘; } arr[i][j]+=2; } } for(int i=n;i>=1;--i) { if(arr[i][j]&4) { memset(vst,0,sizeof(vst)); arr[i][j]-=4; int cur=bfs(i,j); if(cur>maxv) { maxv=cur; maxx=i,maxy=j; maxd=‘E‘; } arr[i][j]+=4; } } } } int main() { std::ios::sync_with_stdio(0); //freopen("d:\\1.txt","r",stdin); lon casenum; //cin>>casenum; //for(lon time=1;time<=casenum;++time) { init(); int block,maxb; work(block,maxb); cout<<block<<endl; cout<<maxb<<endl; int maxv,maxx,maxy; char maxd; work2(maxv,maxx,maxy,maxd); cout<<maxv<<endl; cout<<maxx<<" "<<maxy<<" "<<maxd<<endl; } return 0; }
标签:har names max -- tac tle pac cout queue
原文地址:https://www.cnblogs.com/gaudar/p/9821701.html