Bargaining Table
2 seconds
256 megabytes
standard input
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.
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 one number — the maximum possible perimeter of a bargaining table for Bob's office room.
3 3
000
010
000
8
5 4
1100
0000
0000
0000
0000
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的更多相关文章
- Code Forces 22B Bargaining Table
B. Bargaining Table time limit per test 2 seconds memory limit per test 256 megabytes input standard ...
- 暴力/DP Codeforces Beta Round #22 (Div. 2 Only) B. Bargaining Table
题目传送门 /* 题意:求最大矩形(全0)的面积 暴力/dp:每对一个0查看它左下的最大矩形面积,更新ans 注意:是字符串,没用空格,好事多磨,WA了多少次才发现:( 详细解释:http://www ...
- CF 22B. Bargaining Table
水题.好久没有写过优化搜索题了. #include <cstdio> #include <cstring> #include <iostream> #include ...
- Codeforces 22B Bargaining Table
http://www.codeforces.com/problemset/problem/22/B 题意:求出n*m的方格图中全是0的矩阵的最大周长 思路:枚举 #include<cstdio& ...
- CodeForces 22B Bargaining Table 简单DP
题目很好理解,问你的是在所给的图中周长最长的矩形是多长嗯用坐标(x1, y1, x2, y2)表示一个矩形,暴力图中所有矩形易得递推式:(x1, y1, x2, y2)为矩形的充要条件为: (x1, ...
- S8-codelab02
import news_cnn_model import numpy as np import os import pandas as pd import pickle import shutil i ...
- CF dp 题(1500-2000难度)
前言 从后往前刷 update 新增 \(\text{\color{red}{Mark}}\) 标记功能,有一定难度的题标记为 \(\text{\color{red}{红}}\) 色. 题单 (刷过的 ...
- 散列表(hash table)——算法导论(13)
1. 引言 许多应用都需要动态集合结构,它至少需要支持Insert,search和delete字典操作.散列表(hash table)是实现字典操作的一种有效的数据结构. 2. 直接寻址表 在介绍散列 ...
- React使用antd Table生成层级多选组件
一.需求 用户对不同的应用需要有不同的权限,用户一般和角色关联在一起,新建角色的时候会选择该角色对应的应用,然后对应用分配权限.于是写了一种实现的方式.首先应用是一个二级树,一级表示的是应用分组,二级 ...
随机推荐
- 遇到Intel MKL FATAL ERROR: Cannot load libmkl_avx2.so or libmkl_def.so问题的解决方法
运行一个基于tensorflow的模型时,遇到Intel MKL FATAL ERROR: Cannot load libmkl_avx2.so or libmkl_def.so问题. 解决方法:打开 ...
- 配置EditPlus编辑器使其成为Python的编辑、执行环境
1.添加Python群组 运行EditPlus,选择工具→配置用户工具进入参数设置框. 单击添加工具→应用程序.菜单文字输入python,命令为Python的安装路径,参数输入 $(FileName) ...
- IDEA + SSH OA 第一天(Hibernate : Mapping (RESOURCE) not found)
切入主题,看看今天的错误是如何发生的: 首先这是我的项目路径,java 是 Sources Root , resources 是 Resources Root ,放了所需要的配置文件,其中 Hiber ...
- python处理时间相关的方法(汇总)
记录python处理时间的模块:time模块.datetime模块和calendar模块. python版本:2.7 在介绍模块之前,先说下以下几点: 1.时间通常有这几种表示方式: a.时间戳:通常 ...
- yum源中默认好像是没有mysql的。为了解决这个问题,我们要先下载mysql的repo源。
CentOS7的yum源中默认好像是没有mysql的.为了解决这个问题,我们要先下载mysql的repo源. 1. 下载mysql的repo源 $ wget http://repo.mysql.com ...
- [2017BUAA软工]第一次博客作业
一.一些疑问 看书看得比较慢,暂时只思考了以下几个问题,有些自问自答,不知道符合不符合要求…… [1] 第一章中书上提到了这样一个例子: “如果一架民用飞机上有需求,用户使用它的概率是百万分之一,你还 ...
- phpcms 发布时间 更新 时间
- 【操作系统、UNIX环境编程】进程间通信
多个进程可以共享系统中的各种资源,但其中许多资源一次只能为一个进程使用,我们把一次仅允许一个进程使用的资源称为临界资源,许多物理设备都属于临界资源,如打印机等. Linux下进程间通信有如下几种方式: ...
- hadoop跑第一个实例过程
第一次跑hadoop实例,中间经过了不少弯路,特此记录下来: 第一步:建立一个maven过程,pom.xml文件:(打包为jar包) <dependency> <groupId> ...
- hbase快速入门
hbase 是什么? Apache HBase is an open-source, distributed, versioned, non-relational database modeled a ...