原图找最大的房间及房间数很容易。然后从左下到右上找拆的位置。拆掉再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-;
typedef long long lon;
const lon SZ=,INF=0x7FFFFFFF;
int n,m,arr[SZ][SZ],dx[]={,-,,},dy[]={-,,,};
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=;i<=n;++i)
{
for(int j=;j<=m;++j)cin>>arr[i][j];
}
} int bfs(int bgx,int bgy)
{
int res=;
queue<nd> q;
vst[bgx][bgy]=;
q.push(nd(bgx,bgy));
for(;!q.empty();)
{
nd frt=q.front();
q.pop();
for(int i=;i<;++i)
{
int nx=frt.x+dx[i],ny=frt.y+dy[i];
if(!(arr[frt.x][frt.y]&(<<i))&&nx>=&&nx<=n&&ny>=&&ny<=m&&!vst[nx][ny])
{
vst[nx][ny]=;
q.push(nd(nx,ny));
++res;
}
}
}
return res;
} void work(int &block,int &maxb)
{
block=;
maxb=;
for(int i=;i<=n;++i)
{
for(int j=;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=;
for(int j=;j<=m;++j)
{
for(int i=n;i>=;--i)
{
if(arr[i][j]&)
{
memset(vst,,sizeof(vst));
arr[i][j]-=;
int cur=bfs(i,j);
if(cur>maxv)
{
maxv=cur;
maxx=i,maxy=j;
maxd='N';
}
arr[i][j]+=;
}
}
for(int i=n;i>=;--i)
{
if(arr[i][j]&)
{
memset(vst,,sizeof(vst));
arr[i][j]-=;
int cur=bfs(i,j);
if(cur>maxv)
{
maxv=cur;
maxx=i,maxy=j;
maxd='E';
}
arr[i][j]+=;
}
}
}
} int main()
{
std::ios::sync_with_stdio();
//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 ;
}

p1457 The Castle的更多相关文章

  1. 洛谷P1457 城堡 The Castle

    P1457 城堡 The Castle 137通过 279提交 题目提供者该用户不存在 标签USACO 难度提高+/省选- 提交  讨论  题解 最新讨论 暂时没有讨论 题目描述 我们憨厚的USACO ...

  2. 洛谷 P1457 城堡 The Castle 解题报告

    P1457 城堡 The Castle 题目描述 我们憨厚的USACO主人公农夫约翰(Farmer John)以无法想象的运气,在他生日那天收到了一份特别的礼物:一张"幸运爱尔兰" ...

  3. 洛谷 P1457 城堡 The Castle

    P1457 城堡 The Castle 题目描述 我们憨厚的USACO主人公农夫约翰(Farmer John)以无法想象的运气,在他生日那天收到了一份特别的礼物:一张“幸运爱尔兰”(一种彩票).结果这 ...

  4. P1457 城堡 The Castle

    轻度中毒 原题 :The Castle 以下为题解部分:明明辣么简单的一道题,硬是搞了1.5h,WTF?以下列出本题的一些要点. 搜索(DFS)嘛,染色嘛,统计大小嘛,很容易想,也很更易处理. 接下来 ...

  5. 洛谷—— P1457 城堡 The Castle

    https://www.luogu.org/problem/show?pid=1457 题目描述 我们憨厚的USACO主人公农夫约翰(Farmer John)以无法想象的运气,在他生日那天收到了一份特 ...

  6. 题解 洛谷P1457 【城堡 The Castle】

    这道题,看似很烦,无从下手,但其实只要用位运算和联通快就能水过了呀. 首先,输入:似乎大意是把一个数拆成二进数的相加,分别表示\((i,j)\)东南西北是否有墙.\(1\)表示西,\(2\)表示北,\ ...

  7. 题解 P1457 【城堡 The Castle】

    来讨论区大摇大摆地逛了一圈后,我发现竟然大家的代码 都很长 然而代码真的要写那么长吗 首先,来分析问题,1,2,4,8,这些数显然是有特点的,也许你已经想到了没错,它们都是2的次方数. 1是2的0次方 ...

  8. P1457 城堡 The Castle 位运算+BFS+思维(难题,好题)

    题目描述 我们憨厚的USACO主人公农夫约翰(Farmer John)以无法想象的运气,在他生日那天收到了一份特别的礼物:一张"幸运爱尔兰"(一种彩票).结果这张彩票让他获得了这次 ...

  9. Castle Core 4.0.0 alpha001发布

    时隔一年多以后Castle 项目又开始活跃,最近刚发布了Castle Core 4.0.0 的alpha版本, https://github.com/castleproject/Core/releas ...

随机推荐

  1. error C4996: Function call with parameters that may be unsafe – this call relies on the caller to ch

    在加入QCustomplot时有如题的错误 1>c:\program files (x86)\microsoft visual studio11.0\vc\include\xutility(21 ...

  2. Bootstrap3基础 btn-group-vertical 按钮组(横着、竖着排列)

      内容 参数   OS   Windows 10 x64   browser   Firefox 65.0.2   framework     Bootstrap 3.3.7   editor    ...

  3. Linux下调整ext3分区大小【转】

    本文转载自:https://blog.csdn.net/cruise_h/article/details/22403529 本文讨论如何再不丢失数据的情况下调整已有ext3分区的大小,包括: 压缩已有 ...

  4. js 二叉树删除最大值和最小值

    //删除最小值function delMinNode (root){ if(!root) { return false; } var current = root; if (current.left ...

  5. 论文笔记之:SeqGAN: Sequence generative adversarial nets with policy gradient

    SeqGAN: Sequence generative adversarial nets with policy gradient  AAAI-2017 Introduction :  产生序列模拟数 ...

  6. JAVA基础之复识二

    JAVA语言 未经本人允许禁止转载或使用 基础知识:JAVA数据类型,运算符,流程控制等 注释: // 单行注释 /* 多行连续注释 ... */ /** 文档注释,该类型的注释会生成一个html文件 ...

  7. Oracle Initialzation error instantclient_11_2 32位客户端问题

    本地安装完oracle 用PLSql 连接是一堆的问题,折腾一上午终于解决了 下载一个 instantclient_11_2 32位的oracle客户端.放在oracle安装目录product下,在把 ...

  8. 【BZOJ】4011: [HNOI2015]落忆枫音

    题目链接:http://blog.csdn.net/popoqqq/article/details/45194103 写代码的时候也没有很清晰....具体看这里吧 #include<iostre ...

  9. CentOS7 下更改源

    在CentOS 7下更改yum源与更新系统. [1] 首先备份/etc/yum.repos.d/CentOS-Base.repo cp /etc/yum.repos.d/CentOS-Base.rep ...

  10. Java Object类及其equals方法

    基本概念: Object类位于java.lang包中,java.lang包包含着Java最基础和核心的类,在编译时会自动导入: Object类是所有Java类的祖先.每个类都使用 Object 作为超 ...