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生成层级多选组件
一.需求 用户对不同的应用需要有不同的权限,用户一般和角色关联在一起,新建角色的时候会选择该角色对应的应用,然后对应用分配权限.于是写了一种实现的方式.首先应用是一个二级树,一级表示的是应用分组,二级 ...
随机推荐
- 网站UI分析
本次网站UI分析我选择的是我们石家庄铁道大学的网站,首先对于网站的分析建立在我经常使用鼠须的基础上,我可以很好的站在用户的角度来进行分析,否则对于你不熟悉的网站你可能是不能很好地体验到他的 结构. U ...
- POJ 2484(对称博弈)
题目链接:http://poj.org/problem?id=2484 这道题目大意是这样的,有n个硬币围成一圈,两个人轮流开始取硬币(假设他们编号从1到n),可以选择取一枚或者取相邻的两枚(相邻是指 ...
- [并查集] More is Better
题目描述 Mr Wang wants some boys to help him with a project. Because the project is rather complex, the ...
- HostsConfig文件修改器
Hosts文件修改器 HostsConfig v1.1 免费版 最近工作需要,经常需要更换各种域名的内外网配置,频繁的修改HOSTS文件,很多的时间都用在的修改HOSTS文件上,工作效率大大降低,课余 ...
- Web服务器负载均衡的几种方案 : DNS轮询
本篇主要讲一下最简单的方案——DNS轮询. DNS轮询 大多域名注册商都支持多条A记录 的解析,其实这就是DNS轮询 ,DNS 服务器 将解析请求按照A记录 的顺序,逐一分配到不同的IP上,这样就完成 ...
- Android定位测试(深坑)
问题:我们是一个海外app,市场部去马来西亚打开那边的市场,发现了一个问题,就是我们的app定位有问题,还是成都的定位,主要原因是在马来西亚使用这个app,请求中带的经纬度参数是成都的,导致服务器返回 ...
- Spring boot整合shiro框架
ShiroConfiguration package com.energy.common.config; import java.util.LinkedHashMap; import java.uti ...
- 方法调用时候 传入this 谁调用 传入谁
方法调用时候 传入this 谁调用 传入谁
- 树状数组模板(pascal) 洛谷P3374 【模板】树状数组1
题目描述 如题,已知一个数列,你需要进行下面两种操作: 1.将某一个数加上x 2.求出某区间每一个数的和 输入输出格式 输入格式: 第一行包含两个整数N.M,分别表示该数列数字的个数和操作的总个数. ...
- 【bzoj5123】[Lydsy12月赛]线段树的匹配 树形dp+记忆化搜索
题目描述 求一棵 $[1,n]$ 的线段树的最大匹配数目与方案数. $n\le 10^{18}$ 题解 树形dp+记忆化搜索 设 $f[l][r]$ 表示根节点为 $[l,r]$ 的线段树,匹配选择根 ...