B - Letter(最小覆盖矩形)
Problem description
A boy Bob likes to draw. Not long ago he bought a rectangular graph (checked) sheet with n rows and m columns. Bob shaded some of the squares on the sheet. Having seen his masterpiece, he decided to share it with his elder brother, who lives in Flatland. Now Bob has to send his picture by post, but because of the world economic crisis and high oil prices, he wants to send his creation, but to spend as little money as possible. For each sent square of paper (no matter whether it is shaded or not) Bob has to pay 3.14 burles. Please, help Bob cut out of his masterpiece a rectangle of the minimum cost, that will contain all the shaded squares. The rectangle's sides should be parallel to the sheet's sides.
Input
The first line of the input data contains numbers n and m (1 ≤ n, m ≤ 50), n — amount of lines, and m — amount of columns on Bob's sheet. The following n lines contain m characters each. Character «.» stands for a non-shaded square on the sheet, and «*» — for a shaded square. It is guaranteed that Bob has shaded at least one square.
Output
Output the required rectangle of the minimum cost. Study the output data in the sample tests to understand the output format better.
Examples
Input
6 7
.......
..***..
..*....
..***..
..*....
..***..
Output
***
*..
***
*..
***
Input
3 3
***
*.*
***
Output
***
*.*
***
解题思路:输出最小覆盖所有星号的矩形。
AC代码:
#include<bits/stdc++.h>
using namespace std;
int main(){
int n,m,rou,rod,colt,cort;char s[][];
cin>>n>>m;getchar();
rou=n-,rod=,colt=m-,cort=;
for(int i=;i<n;++i)
for(int j=;j<m;++j)
cin>>s[i][j];
for(int i=;i<n;++i){
int j=,k=m-;
while(j<m && s[i][j]=='.')j++;
while(k>= && s[i][k]=='.')k--;
if(j<=k){
colt=min(colt,j);cort=max(cort,k);//确定列的左右最大范围
rou=min(i,rou);rod=max(rod,i);//确定行的上下最大范围
}
}
for(int i=rou;i<=rod;++i){
for(int j=colt;j<=cort;++j)cout<<s[i][j];
cout<<endl;
}
return ;
}
B - Letter(最小覆盖矩形)的更多相关文章
- [matlab] 10.最小覆盖
clear all; close all; clc; n=100; p=rand(n,2); p1=p(1,:); %取第一行的值 P1点 p2=p(2,:); %取第二行的值 P2点 r=sqrt( ...
- BZOJ 1185 [HNOI2007]最小矩形覆盖:凸包 + 旋转卡壳
题目链接:https://www.lydsy.com/JudgeOnline/problem.php?id=1185 题意: 给出二维平面上的n个点,问你将所有点覆盖的最小矩形面积. 题解: 先找出凸 ...
- ACM/ICPC竞赛
ACM知识点分类 第一类:基础算法 (1) 基础算法:枚举,贪心,递归,分治,递推,构造,模拟 (2) 动态规划:背包问题,树形dp,状态压缩dp,单调性优化,插头dp (3) 搜索:dfs,bf ...
- ACM知识点分类
(知识点分类.看完想(╯‵□′)╯︵┻━┻) orz...一点点来吧.简单标记一下. 蓝色,比较熟悉,能够做. 蓝绿色,一般熟悉,需要加强 红色,(比个辣鸡.jpg) (标记完突然想打人...) 第一 ...
- CS53 C 单调栈
给出一个目标序列,初始序列为0,你有一种操作方式可以将某段值相同的区间全部加上一定的值,问得到目标序列的最小次数. 开始没注意要求值相同,想都不想就暴力了,后来发现对于每个峰,只要找每个相对峰顶的阶数 ...
- 2016.4.3NOI上较难的动规题目(仔细分析样例)--王老师讲课整理
1.NOI 191:钉子和小球 总时间限制: 1000ms 内存限制: 65536kB 描述 有一个三角形木板,竖直立放,上面钉着n(n+1)/2颗钉子,还有(n+1)个格子(当n=5时如图1).每 ...
- 【leetcode】302.Smallest Rectangle Enclosing Black Pixels
原题 An image is represented by a binary matrix with 0 as a white pixel and 1 as a black pixel. The bl ...
- [opencv]findcoutours函数使用
轮廓是定义或限定形状或对象的边或线,是机器视觉中的常用的概念,多用于目标检测.识别等任务. 关于OpenCV轮廓操作,尤其是级别及如何使用轮廓级别进行筛选等问题,相关文章比较少,正好最近用到,因此将其 ...
- POJ2185Milking Grid(最小覆盖子串 + 二维KMP)
题意: 一个r*c的矩形,求一个子矩形通过平移复制能覆盖整个矩形 关于一个字符串的最小覆盖子串可以看这里http://blog.csdn.net/fjsd155/article/details/686 ...
随机推荐
- WPF度量系統
和Winform不同,WPF的度量單位不是像素,而是設備無關單位DIU,其大小總是1/96吋 那麽,WPF中一個寬度爲96的按鈕,到底是多少個像素呢? 答:取決於系統DPI. 計算公式爲:實際像素 = ...
- 安卓系统使用摄像头API
原文链接:定制自己的安卓Camera 参考链接:http://blog.csdn.net/tankai19880619/article/details/9075839 ...
- [Intermediate Algorithm] - Everything Be True
题目 所有的东西都是真的! 完善编辑器中的every函数,如果集合(collection)中的所有对象都存在对应的属性(pre),并且属性(pre)对应的值为真.函数返回ture.反之,返回false ...
- Spring MVC 中的基于注解的 Controller(转载)
终于来到了基于注解的 Spring MVC 了.之前我们所讲到的 handler,需要根据 url 并通过 HandlerMapping 来映射出相应的 handler 并调用相应的方法 ...
- java 基础回顾1
整理----加自己理解------网上参考----- java封装理念 一 概念: 隐藏对象的属性和实现细节,仅供对外提供公共访问方式. 二 好处 1) 将变量隔离 2) 便于使用 3) 提高重 ...
- 面试官问你:MYSQL事务和隔离级别,该如何回答
一.事务 事务是由一组SQL语句组成的逻辑处理单元,是满足 ACID 特性的一组操作,可以通过 Commit 提交一个事务,也可以使用 Rollback 进行回滚.事务具有以下4个属性,通常简称为事务 ...
- springMVC返回汉字字符串乱码,以及返回的字符串乱码的问题
1.springMVC在使用@ResponseBody注解返回字符串为什么出现乱码呢?(这里以spring4.3.1为例) 原因分析:原因在返回字符串时StringHttpMessageConvert ...
- eoLinker GoKu Gateway 开源版 V2.1发布,加入UI管理系统等
GoKu API Gateway 是eoLinker旗下的开源版接口网关,支持OpenAPI与微服务管理,支持私有云部署,实现API转发.请求参数转换.数据校验等功能,提供图形化界面管理,能够快速管理 ...
- Linux 僵尸进程如何处理
Linux 允许进程查询内核以获得其父进程的 PID,或者其任何子进程的执行状态.例如,进程可以创建一个子进程来执行特定的任务,然后调用诸如 wait() 这样的一些库函数检查子进程是否终止.如果子进 ...
- HDU 1241 Oil Deposits (DFS or BFS)
链接 : Here! 思路 : 搜索判断连通块个数, 所以 $DFS$ 或则 $BFS$ 都行喽...., 首先记录一下整个地图中所有$Oil$的个数, 然后遍历整个地图, 从油田开始搜索它所能连通多 ...