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. BAT批处理

    常用命令 查看目录内容命令dir 指定可执行文件搜索目录path 创建目录命令md 打开指定目录命令cd 删除当前指定的子目录命令rd 改变当前盘符命令d: 文件复制命令copy 显示文本文件内容命令 ...

  2. [POJ 1004] Financial Management C++解题

    参考:https://www.cnblogs.com/BTMaster/p/3525008.html #include <iostream> #include <cstdio> ...

  3. Ubuntn14.04安装MATLAB2015b

    一部分转载自:CSDN ,其他结合自己电脑环境配置,旨做备份和记录,同时也提供一个参考. 安装环境: linux Ubuntu14.04 (x64) 软件包下载地址: Matlab R2015b_gl ...

  4. 『JavaScript』new关键字

    原文 new关键字做了什么 在JavaScript中,使用new关键字后,意味着做了如下四件事情: 创建一个新的对象,这个对象的类型是object: 设置这个新的对象的内部.可访问性和[[protot ...

  5. 如何修改Github上提交的错误用户地址和姓名

    Changing author info  https://help.github.com/articles/changing-author-info/   To change the name an ...

  6. VIN码识别:助力汽车后市场转型升级

    随着中国汽车市场的成熟,汽车后市场发展迅速,呈“井喷”式增长.据最新数据统计,2015年,中国汽车后市场产值突破8000亿规模,到2018年有望突破万亿. 所谓汽车后市场是指汽车销售以后,围绕汽车使用 ...

  7. Spring实战第九章学习笔记————保护Web应用

    保护Web应用 在这一章我们将使用切面技术来探索保护应用程序的方式.不过我们不必自己开发这些切面----我们将使用Spring Security,一种基于Spring AOP和Servlet规范的Fi ...

  8. PHP中的6种加密方式

    PHP中的6种加密方式 1. MD5加密 string md5 ( string $str [, bool $raw_output = false ] ) 参数 str  --  原始字符串. raw ...

  9. PokeCats开发者日志(三)

      现在是PokeCats游戏开发的第四天的晚上,明天要过周末了,所以提前写一下开发者日志吧! day4   day4主要是优化界面和增加游戏可玩性.   (1)感觉只有三只喵喵的话,玩家只需要无脑点 ...

  10. 【工具学习】——Maven的安装与配置

    [含义] 什么是构建? 构建,英文build.构建包括编译.运行.生成文档.打包.部署等等工作内容,如果我们每天手工去干这些事情,那会浪费很多的时间.因此,构建管理工具应运而生. maven,作为项目 ...