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 ...
随机推荐
- CXF-JAX-RS开发(一)入门案例
一.简介 资源驱动.基于HTTP协议[按照标准指定URL,就可以访问数据]以XML|JSON格式传输数据. 二.quickstart 1.创建maven project[Packaging:jar] ...
- 【转载】浏览器缓存详解:expires cache-control last-modified
https://www.cnblogs.com/caiyanhu/p/6931624.html 下面的内容展示了一个常见的 Response Headers,这些 Headers 要求客户端最多缓存 ...
- Crossing Rivers UVA - 12230 概率与期望
题目大意:有个人每天要去公司上班,每次会经过N条河,家和公司的距离为D,默认在陆地的速度为1,给出N条河的信息,包括起始坐标p,宽度L,以及船的速度v.船会往返在河的两岸,人到达河岸时,船的位置是随机 ...
- python jieba分词(添加停用词,用户字典 取词频
中文分词一般使用jieba分词 1.安装 pip install jieba 2.大致了解jieba分词 包括jieba分词的3种模式 全模式 import jieba seg_list = jieb ...
- python 生成HTmL报告页面 V1.2
上代码 # -*- coding=utf-8 -*- import time,os #数据部分 func_dict={"funcname":"模块1",} fu ...
- Apache2.4更改默认根目录并配置虚拟域名
软件环境: 1.virtualbox中安装Ubuntu 16.04-server 2.window7下安装Xshell5 以上安装好后, 1.设置virtualbox网络为桥接网卡,启动Ubuntu. ...
- PHP 设计模式之工厂模式 (静态工厂模式)
### 工厂模式: 由工厂类根据参数来决定创建出哪一种产品类的实例.工厂类是指包含了一个专门用来创建其他对象的方法的类.所谓按需分配,传入参数进行选择,返回具体的类.工厂模式的最主要作用就是对象创建的 ...
- 继续聊WPF
下面看一个Tick控件的例子,这只是演示,Tick单独使用没有意义. <TickBar Height="15" Width="180" Ticks=&qu ...
- qtp12版本下载安装破解教程
下载链接:https://download.csdn.net/download/weixin_41479750/11240466 下面是安装教程: 解压完成之后,双击运行setup.exe 之后点击运 ...
- JavaSE 学习笔记之面向对象(三)
面向对象 特点: 1:将复杂的事情简单化. 2:面向对象将以前的过程中的执行者,变成了指挥者. 3:面向对象这种思想是符合现在人们思考习惯的一种思想. 过程和对象在我们的程序中是如何体现的呢?过程 ...