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 ...
随机推荐
- layer自定义弹窗样式
1.下载并引用js, 官网http://layer.layui.com/ 文档http://www.layui.com/doc/modules/layer.html <link href=&qu ...
- Apex语言(五)循环结构
1.循环结构 循环语句允许我们多次执行一个语句或一组语句(重执行语句). 2.while语句 只要给定条件为真,目标语句就会重复执行. [格式] while (循环条件){ 语句; } [流程图] ...
- HTML 5语义化标签
HTML 5的革新之一:语义化标签一节元素标签. 在HTML 5出来之前,我们用div来表示页面章节,但是这些div都没有实际意义.(即使我们用css样式的id和class形容这块内容的意义).这些标 ...
- matlab学习下拉菜单Pop-Up Menu的基本用法
创建下拉菜单,修改string的属性,tag改为kj1,value值如果是1就显示第一行的sin(x),是几就显示第几行 %可以更改value值var=get(handles.kj1,'value') ...
- C#连接Oracle数据库的方法(System.Data.OracleClient、Oracle.DataAccess.Client也叫ODP.net、Oracle.ManagedDataAccess.dll)
官方下载地址(ODP.net)(中文):http://www.oracle.com/technetwork/cn/topics/dotnet/downloads/index.html 官方下载地址(O ...
- jQuery默认select选择第一个元素
$("#id option:first").prop("selected", 'selected');
- VUE常见问题解决
1.vue模板加载顺序 computed:例如分页的配置: created:dom加载前一般用来生成dom mounted:dom加载后用来覆盖渲染或者基于dom的操作 2.关于this指向的问题 通 ...
- BZOJ 3744 Gty的妹子序列 (分块+树状数组+主席树)
题面传送门 题目大意:给你一个序列,多次询问,每次取出一段连续的子序列$[l,r]$,询问这段子序列的逆序对个数,强制在线 很熟悉的分块套路啊,和很多可持久化01Trie的题目类似,用分块预处理出贡献 ...
- jquery 绑定回车(Enter )事件
全局: $(function(){ document.onkeydown = function(e){ var ev = document.all ? window.event : e; if(ev. ...
- 【例题4-2 uva489】Hangman Judge
[链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] 水题. 中间就赢了算赢.(重复说,算错 [代码] #include <bits/stdc++.h> using name ...