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. uva 509 RAID!(磁盘数据)

    来自 https://blog.csdn.net/su_cicada/article/details/80085318 习题4-7 RAID技术(RAID!, ACM/ICPC World Final ...

  2. fiddler手机抓包配置方法

    一.下载工具包 百度搜索”fiddler 下载“ ,安装最新版本 下载的软件安装包为“fiddler_4.6.20171.26113_setup.exe”格式,双击安装.安装成功,在“开始”-“所有程 ...

  3. Spring 中的文件上传与下载控制

    先创建根应用上下文配置,WebDemo/src/main/java/com/seliote/webdemo/config/RootContextConfig.java package com.seli ...

  4. DecimalFormat的用法

    DecimalFormat 是 NumberFormat 的一个具体子类,用于格式化十进制数字. DecimalFormat 包含一个模式 和一组符符号含义:  0 一个数字 # 一个数字,不包括 0 ...

  5. 清除远程桌面连接记录和SQLSERVER 连接记录的办法

    1.清除远程桌面连接记录: 清除远程桌面访问痕迹.使用windows系统自带的“远程桌面协助”mstsc进行远程,如果连接的用户多了,会留下访问的痕迹.虽然能带来方便,但是如果对于公用电脑来说,这些访 ...

  6. JavaScript函数constructor的作用,意义

    前几天写了一片 如何用正确的姿势编写jQuery插件 有朋友拍砖,指正.再此谢谢! 讨论:指定函数的constructor作用到底是什么? 我们一般写jQuery插件的时候是这样的: //构造函数 f ...

  7. 第二篇 Fiddler配置_浏览器&手机

    什么是Fiddler? 网络项目的开发和测试中,Fiddler是强大的抓包工具,它的原理是以web代理服务器的形式进行工作的 ,可以说是非常常用的手头工具了,本文就Fiddler使用和配置进行说明. ...

  8. python 网络编程(远程执行命令与粘包)

    远程执行命令 先来学习一个新模块 , 一会用到的.. 新模块: subprocess 执行系统命令 r = subprocess.Popen('ls',shell=True,stdout=subpro ...

  9. kubernetes(k8s) 集群

    开启和重启命令: sudo systemctl stop etcdsudo systemctl stop dockersudo systemctl stop kube-apiserversudo sy ...

  10. 【SSH】——Struts2中的动态方法调用(一)

    首先我们来看一个简单的调用: 1.在web.xml中配置拦截器StrutsPrepareAndExecuteFilter.StrutsPrepareAndExecuteFilter实现了filter接 ...