Bargaining Table
time limit per test

2 seconds

memory limit per test

256 megabytes

input

standard input

output

standard output

Bob wants to put a new bargaining table in his office. To do so he measured the office room thoroughly and drew its plan: Bob's office room is a rectangular room n × m meters. Each square meter of the room is either occupied by some furniture, or free. A bargaining table is rectangular, and should be placed so, that its sides are parallel to the office walls. Bob doesn't want to change or rearrange anything, that's why all the squares that will be occupied by the table should be initially free. Bob wants the new table to sit as many people as possible, thus its perimeter should be maximal. Help Bob find out the maximum possible perimeter of a bargaining table for his office.

Input

The first line contains 2 space-separated numbers n and m (1 ≤ n, m ≤ 25) — the office room dimensions. Then there follow n lines with m characters 0 or 1 each. 0 stands for a free square meter of the office room. 1 stands for an occupied square meter. It's guaranteed that at least one square meter in the room is free.

Output

Output one number — the maximum possible perimeter of a bargaining table for Bob's office room.

Sample test(s)
input
3 3
000
010
000
output
8
input
5 4
1100
0000
0000
0000
0000
output
16

这题该怎么说呢,不难,但是又做了挺久。。。

遍历每一个点vi,算出以vi为左上角的谈判桌的最大周长p(vi),取max(p(vi))。有一些简单的剪枝操作,也不值一提。

AC Code:

 #include <iostream>
#include <algorithm>
#include <string>
#include <queue>
#include <vector>
#include <cmath>
#include <cstdio>
#include <cstring>
using namespace std; const int SZ = ;
char map[SZ][SZ];
int n, m; int Solve(int y, int x)
{
int w = , d, maxP = ;
for(int i = y; i < n; i++)
{
int j;
for(j = x; j < m; j++)
{
if(map[i][j] == '') break;
}
if(j != x) d = i - y + ;
else break;
if(w > j - x) w = j - x;
int t = (d + w) << ;
if(t > maxP) maxP = t;
}
return maxP;
} int main()
{
while(scanf("%d %d", &n, &m) != EOF)
{
for(int i = ; i < n; i++)
scanf("%s", map[i]);
int maxP = ;
for(int i = ; i < n; i++)
{
for(int j = ; j < m; j++)
{
if(map[i][j] == '')
{
int t = Solve(i , j);
if(maxP < t) maxP = t;
}
}
}
printf("%d\n", maxP);
}
return ;
}

Bargaining Table的更多相关文章

  1. Code Forces 22B Bargaining Table

    B. Bargaining Table time limit per test 2 seconds memory limit per test 256 megabytes input standard ...

  2. 暴力/DP Codeforces Beta Round #22 (Div. 2 Only) B. Bargaining Table

    题目传送门 /* 题意:求最大矩形(全0)的面积 暴力/dp:每对一个0查看它左下的最大矩形面积,更新ans 注意:是字符串,没用空格,好事多磨,WA了多少次才发现:( 详细解释:http://www ...

  3. CF 22B. Bargaining Table

    水题.好久没有写过优化搜索题了. #include <cstdio> #include <cstring> #include <iostream> #include ...

  4. Codeforces 22B Bargaining Table

    http://www.codeforces.com/problemset/problem/22/B 题意:求出n*m的方格图中全是0的矩阵的最大周长 思路:枚举 #include<cstdio& ...

  5. CodeForces 22B Bargaining Table 简单DP

    题目很好理解,问你的是在所给的图中周长最长的矩形是多长嗯用坐标(x1, y1, x2, y2)表示一个矩形,暴力图中所有矩形易得递推式:(x1, y1, x2, y2)为矩形的充要条件为: (x1, ...

  6. S8-codelab02

    import news_cnn_model import numpy as np import os import pandas as pd import pickle import shutil i ...

  7. CF dp 题(1500-2000难度)

    前言 从后往前刷 update 新增 \(\text{\color{red}{Mark}}\) 标记功能,有一定难度的题标记为 \(\text{\color{red}{红}}\) 色. 题单 (刷过的 ...

  8. 散列表(hash table)——算法导论(13)

    1. 引言 许多应用都需要动态集合结构,它至少需要支持Insert,search和delete字典操作.散列表(hash table)是实现字典操作的一种有效的数据结构. 2. 直接寻址表 在介绍散列 ...

  9. React使用antd Table生成层级多选组件

    一.需求 用户对不同的应用需要有不同的权限,用户一般和角色关联在一起,新建角色的时候会选择该角色对应的应用,然后对应用分配权限.于是写了一种实现的方式.首先应用是一个二级树,一级表示的是应用分组,二级 ...

随机推荐

  1. CS小分队第二阶段冲刺站立会议(5月30日)

    昨日成果:解决了前天遗留的问题,实现了主界面对于电脑上应用的添加和删除 遇到问题:添加和删除按钮时候,按钮位置图像与北京图片冲突,会出现闪动现象. 删除是通过右键单击出现菜单,其中有删除的选项,但是这 ...

  2. is-A继承?Has-A?

    教程把is-A和Has-A放在一起,我还以为java支持简单的方法能把Has对象的方法导出呢..   extents  implements 要试一下. 不知道狗和汽车为什么总是被选出来举例.   p ...

  3. 博弈--ZOJ 3084 S-Nim(SG)

    题意: 首先输入K 表示一个集合的大小  之后输入集合 表示对于这对石子只能去这个集合中的元素的个数 之后输入 一个m 表示接下来对于这个集合要进行m次询问  之后m行 每行输入一个n 表示有n个堆  ...

  4. PAT L1-032 Left-pad

    https://pintia.cn/problem-sets/994805046380707840/problems/994805100684361728 根据新浪微博上的消息,有一位开发者不满NPM ...

  5. workstation vmware 制作vm模板

    [root@VM166136 ~]# cat copy_vmware.sh #!/bin/bash if [ $(id -u) -ne 0 ];then echo "Please use t ...

  6. Spring Cloud 架构 五大神兽的功能

    什么是微服务 微服务的概念源于2014年3月Martin Fowler所写的一篇文章“Microservices”. 微服务架构是一种架构模式,它提倡将单一应用程序划分成一组小的服务,服务之间互相协调 ...

  7. 【JavaScript&jQuery】$.ajax()

    $(function(){ $('#send').click(function(){ $.ajax({ type: "GET", url: "test.json" ...

  8. (转)Redis使用详细教程

    转载至http://www.cnblogs.com/wangyuyu/p/3786236.html 一.Redis基础部分: 1.redis介绍与安装比mysql快10倍以上 ************ ...

  9. P2475 [SCOI2008]斜堆

    题目背景 四川2008NOI省选 题目描述 斜堆(skew heap)是一种常用的数据结构.它也是二叉树,且满足与二叉堆相 同的堆性质:每个非根结点的值都比它父亲大.因此在整棵斜堆中,根的值最小. 但 ...

  10. web框架引入

    1. web请求的本质就是一个socket. 2.http:一次请求,一次响应,断开链接.如下程序:必须先运行服务器端,然后客户端才能去连接.所有web框架的本质就是如下: import socket ...