p1457 The Castle
原图找最大的房间及房间数很容易。然后从左下到右上找拆的位置。拆掉再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的更多相关文章
- 洛谷P1457 城堡 The Castle
P1457 城堡 The Castle 137通过 279提交 题目提供者该用户不存在 标签USACO 难度提高+/省选- 提交 讨论 题解 最新讨论 暂时没有讨论 题目描述 我们憨厚的USACO ...
- 洛谷 P1457 城堡 The Castle 解题报告
P1457 城堡 The Castle 题目描述 我们憨厚的USACO主人公农夫约翰(Farmer John)以无法想象的运气,在他生日那天收到了一份特别的礼物:一张"幸运爱尔兰" ...
- 洛谷 P1457 城堡 The Castle
P1457 城堡 The Castle 题目描述 我们憨厚的USACO主人公农夫约翰(Farmer John)以无法想象的运气,在他生日那天收到了一份特别的礼物:一张“幸运爱尔兰”(一种彩票).结果这 ...
- P1457 城堡 The Castle
轻度中毒 原题 :The Castle 以下为题解部分:明明辣么简单的一道题,硬是搞了1.5h,WTF?以下列出本题的一些要点. 搜索(DFS)嘛,染色嘛,统计大小嘛,很容易想,也很更易处理. 接下来 ...
- 洛谷—— P1457 城堡 The Castle
https://www.luogu.org/problem/show?pid=1457 题目描述 我们憨厚的USACO主人公农夫约翰(Farmer John)以无法想象的运气,在他生日那天收到了一份特 ...
- 题解 洛谷P1457 【城堡 The Castle】
这道题,看似很烦,无从下手,但其实只要用位运算和联通快就能水过了呀. 首先,输入:似乎大意是把一个数拆成二进数的相加,分别表示\((i,j)\)东南西北是否有墙.\(1\)表示西,\(2\)表示北,\ ...
- 题解 P1457 【城堡 The Castle】
来讨论区大摇大摆地逛了一圈后,我发现竟然大家的代码 都很长 然而代码真的要写那么长吗 首先,来分析问题,1,2,4,8,这些数显然是有特点的,也许你已经想到了没错,它们都是2的次方数. 1是2的0次方 ...
- P1457 城堡 The Castle 位运算+BFS+思维(难题,好题)
题目描述 我们憨厚的USACO主人公农夫约翰(Farmer John)以无法想象的运气,在他生日那天收到了一份特别的礼物:一张"幸运爱尔兰"(一种彩票).结果这张彩票让他获得了这次 ...
- Castle Core 4.0.0 alpha001发布
时隔一年多以后Castle 项目又开始活跃,最近刚发布了Castle Core 4.0.0 的alpha版本, https://github.com/castleproject/Core/releas ...
随机推荐
- You have new mail in /var/spool/mail/root
centos7.5 查看邮件的方式: [root@web01 code]# yum -y install mailx #安装mailx [root@web01 code]# mail #执行mail命 ...
- Spring Security原理与应用
Spring Security是什么 Spring Security是一个能够为基于Spring的企业应用系统提供声明式的安全访问控制解决方案的安全框架.它提供了一组可以在Spring应用上下文中配置 ...
- 【MVC】Spring MVC常用配置
一.SpringMVC基础入门,创建一个HelloWorld程序 1.首先,导入SpringMVC需要的jar包. 2.添加Web.xml配置文件中关于SpringMVC的配置 <!--conf ...
- shiro中authc和user的权限区别
前者(authc)是认证过,后者(user)是登录过,如果开启了rememberMe功能的话,后者(user)也是可以通过的,而前者(authc)通过不了.故我们用authc来校验一些关键操作,比如购 ...
- Derek解读Bytom源码-启动与停止
作者:Derek 简介 Github地址:https://github.com/Bytom/bytom Gitee地址:https://gitee.com/BytomBlockchain/bytom ...
- POJ 3279 Fliptile(翻格子)
POJ 3279 Fliptile(翻格子) Time Limit: 2000MS Memory Limit: 65536K Description - 题目描述 Farmer John kno ...
- Lintcode214-Max of Array-Naive
Given an array with couple of float numbers. Return the max value of them. Example Example 1: Input: ...
- SAP应用创新-维护控制表、视图统一路径
SAP应用创新-维护控制表.视图统一路径 背景: Sap 里面通过技术支持人员维护表的值控制业务操作的表不少,一般通过事物代码或记录在系统外的文档或在某个程序上放置一个按钮.缺点:分散,不易记,不好找 ...
- Windows has encountered a critical problem and will restart automatically in one minute. Please save your work now
Windows has encountered a critical problem and will restart automatically in one minute. Please save ...
- Model中时间格式化
MVC 中 @Html中的时间格式化 @Html.TextBoxFor(model => model.StartTime, "{0:yyyy-MM-dd HH:mm:ss}" ...