E1. Stars Drawing (Easy Edition)
time limit per test

3 seconds

memory limit per test

256 megabytes

input

standard input

output

standard output

A star is a figure of the following type: an asterisk character '*' in the center of the figure and four rays (to the left, right, top, bottom) of the same positive length. The size of a star is the length of its rays. The size of a star must be a positive number (i.e. rays of length 00 are not allowed).

Let's consider empty cells are denoted by '.', then the following figures are stars:

The leftmost figure is a star of size 11, the middle figure is a star of size 22 and the rightmost figure is a star of size 33.

You are given a rectangular grid of size n×mn×m consisting only of asterisks '*' and periods (dots) '.'. Rows are numbered from 11 to nn, columns are numbered from 11 to mm. Your task is to draw this grid using any number of stars or find out that it is impossible. Stars can intersect, overlap or even coincide with each other. The number of stars in the output can't exceed n⋅mn⋅m. Each star should be completely inside the grid. You can use stars of same and arbitrary sizes.

In this problem, you do not need to minimize the number of stars. Just find any way to draw the given grid with at most n⋅mn⋅m stars.

Input

The first line of the input contains two integers nn and mm (3≤n,m≤1003≤n,m≤100) — the sizes of the given grid.

The next nn lines contains mm characters each, the ii-th line describes the ii-th row of the grid. It is guaranteed that grid consists of characters '*' and '.' only.

Output

If it is impossible to draw the given grid using stars only, print "-1".

Otherwise in the first line print one integer kk (0≤k≤n⋅m0≤k≤n⋅m) — the number of stars needed to draw the given grid. The next kk lines should contain three integers each — xjxj, yjyj and sjsj, where xjxj is the row index of the central star character, yjyj is the column index of the centralstar character and sjsj is the size of the star. Each star should be completely inside the grid.

Examples
input

Copy
6 8
....*...
...**...
..*****.
...**...
....*...
........
output

Copy
3
3 4 1
3 5 2
3 5 1
input

Copy
5 5
.*...
****.
.****
..**.
.....
output

Copy
3
2 2 1
3 3 1
3 4 1
input

Copy
5 5
.*...
***..
.*...
.*...
.....
output

Copy
-1
input

Copy
3 3
*.*
.*.
*.*
output

Copy
-1
Note

In the first example the output

2
3 4 1
3 5 2

is also correct.

题意:给你一个大小为n*m的图,求其中‘*’的十字架大小

题解:暴力,记得给走过的路打标记

代码如下:

#include <map>
#include <set>
#include <cmath>
#include <ctime>
#include <stack>
#include <queue>
#include <cstdio>
#include <cctype>
#include <bitset>
#include <string>
#include <vector>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <functional>
#define fuck(x) cout<<"["<<x<<"]";
#define FIN freopen("input.txt","r",stdin);
#define FOUT freopen("output.txt","w+",stdout);
//#pragma comment(linker, "/STACK:102400000,102400000")
using namespace std;
typedef long long LL;
typedef pair<int, int> PII;
const int maxn = ;
char str[maxn][maxn];
bool vis[maxn][maxn];
int n,m;
struct node {
int x,y,cnt;
}; std::vector<node> v; bool check(int x,int y,int r){
if(x+r>=n||x-r<||y+r>=m||y-r<) return ;
return ;
} int main(){
#ifndef ONLINE_JUDGE
FIN
#endif scanf("%d%d",&n,&m);
for(int i=;i<n;i++){
scanf("%s",str[i]);
} for(int i=;i<n;i++){
for(int j=;j<m;j++){
int cnt=;
if(str[i][j]=='*'){
for(int a=; ;a++){
if(check(i,j,a)){
if(str[i+a][j]=='*'&&str[i-a][j]=='*'&&str[i][j+a]=='*'&&str[i][j-a]=='*'){
cnt++;
vis[i+a][j] = vis[i-a][j] = vis[i][j+a] = vis[i][j-a] = ; //求十字架的长度
vis[i][j] = ;
}else break;
}else break;
}
}
if (cnt != )
v.push_back(node{i+, j+, cnt});
}
} bool ok = ;
for (int i = ; i < n; i++){
for (int j = ; j < m; j++){
if (str[i][j] == '*' && !vis[i][j]){
ok = ;
break;
}
}
} if (!ok){
printf("-1\n"); }else{
printf("%d\n", v.size());
for (int i = ; i < v.size(); i++){
printf("%d %d %d\n", v[i].x, v[i].y, v[i].cnt);
}
} }

codeforces 1015E1&&E2的更多相关文章

  1. Codeforces 1005 E2 - Median on Segments (General Case Edition)

    E2 - Median on Segments (General Case Edition) 思路: 首先我们计算出solve(m):中位数大于等于m的方案数,那么最后答案就是solve(m) - s ...

  2. Codeforces 1015E1 Stars Drawing (Easy Edition)

    题面: 传送门 题目描述: 要求用十字星星来画题目给出的"星"图.如果不能用十字星星来画"星"图,输出-1:如果能,则输出要在图的哪个位置画相应大小的十字星图. ...

  3. Codeforces 1108E2 Array and Segments (Hard version) 差分, 暴力

    Codeforces 1108E2 E2. Array and Segments (Hard version) Description: The only difference between eas ...

  4. Codeforces Round #535 (Div. 3) E2. Array and Segments (Hard version) 【区间更新 线段树】

    传送门:http://codeforces.com/contest/1108/problem/E2 E2. Array and Segments (Hard version) time limit p ...

  5. codeforces 391E2 (【Codeforces Rockethon 2014】E2)

    题目:http://codeforces.com/problemset/problem/391/E2    题意:有三棵树.每棵树有ni个结点,加入两条边把这三棵树连接起来,合并成一棵树.使得合并的树 ...

  6. CodeForces -Codeforces Round #496 (Div. 3) E2. Median on Segments (General Case Edition)

    参考:http://www.cnblogs.com/widsom/p/9290269.html 传送门:http://codeforces.com/contest/1005/problem/E2 题意 ...

  7. Codeforces Round #584 E2. Rotate Columns (hard version)

    链接: https://codeforces.com/contest/1209/problem/E2 题意: This is a harder version of the problem. The ...

  8. Codeforces Round #567 (Div. 2) E2 A Story of One Country (Hard)

    https://codeforces.com/contest/1181/problem/E2 想到了划分的方法跟题解一样,但是没理清楚复杂度,很难受. 看了题解觉得很有道理,还是自己太菜了. 然后直接 ...

  9. Codeforces Round #617 (Div. 3) String Coloring(E1.E2)

    (easy version): 题目链接:http://codeforces.com/contest/1296/problem/E1 题目一句话就是说,两种颜色不同的字符可以相互换位, 问,对这字符串 ...

随机推荐

  1. Eclipse报错:An internal error occurred during: "Building workspace". Java heap space),卡死解决办法

    在项目工程的根目录下,找到.project,用记事本打开,把两处删除掉: 第一处: <buildCommand> <name>org.eclipse.wst.jsdt.core ...

  2. MUI:字符串和json数据的相互转换

    JSON.parse()--字符串转换json.JSON.stringify()--json转换成字符串 如:收到Json对象:response,则: {"result":&quo ...

  3. 设计模式——模版方法模式详解(论沉迷LOL对学生的危害)

    .  实例介绍 在本例中,我们使用一个常见的场景,我们每个人都上了很多年学,中学大学硕士,有的人天生就是个天才,中学毕业就会微积分,因此得了诺贝尔数学奖:也有的人在大学里学了很多东西,过得很充实很满意 ...

  4. 在Linux中安装和配置OpenVPN Server的最简便方法!

    本文介绍了如何在基于RPM和DEB的系统中安装和配置OpenVPN服务器.我们在本文中将使用一个名为openvpn-install的脚本,它使整个OpenVPN服务器的安装和配置过程实现了自动化.该脚 ...

  5. NLP系列-中文分词(基于词典)

    中文分词概述 词是最小的能够独立活动的有意义的语言成分,一般分词是自然语言处理的第一项核心技术.英文中每个句子都将词用空格或标点符号分隔开来,而在中文中很难对词的边界进行界定,难以将词划分出来.在汉语 ...

  6. Struts2—整合Spring

    Struts2—整合Spring Spring框架是一个非常优秀的轻量级java EE容器,大部分javaEE应用,都会考虑使用Spring容器来管理应用中的组件. Struts2是一个MVC框架,是 ...

  7. 最短路径——Dijkstra算法以及二叉堆优化(含证明)

    一般最短路径算法习惯性的分为两种:单源最短路径算法和全顶点之间最短路径.前者是计算出从一个点出发,到达所有其余可到达顶点的距离.后者是计算出图中所有点之间的路径距离. 单源最短路径 Dijkstra算 ...

  8. 编程练习:寻找发帖"水王"扩展问题二

    回顾 在前面两篇文章已经实现了水王id出现次数超过一半,以及水王id出现次数刚好一半 分析 借助上面水王id出现次数刚好出现一半的分析,其实这里就是找出数组中出现次数前三的元素,具体的分析,见前面两篇 ...

  9. lintcode-110-最小路径和

    110-最小路径和 给定一个只含非负整数的m*n网格,找到一条从左上角到右下角的可以使数字和最小的路径. 注意事项 你在同一时间只能向下或者向右移动一步 样例 标签 动态规划 思路 使用动态规划,用二 ...

  10. 利用Github Pages建立仓库“门面”

    嘛是Github Pages? Github Pages 是一个静态网站托管服务,用来从你的Github仓库中直接发布 个人.组织或项目的网站页面 Github Pages发布的页面统一使用githu ...