E1. Stars Drawing (Easy Edition)
time limit per test
3 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

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 0 are not allowed).

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

codeforces 1015E1&&E2The leftmost figure is a star of size 3.

You are given a rectangular grid of size n⋅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⋅m stars.

Input

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

The next .' only.

Output

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

Otherwise in the first line print one integer 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 = 1005;
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<0||y+r>=m||y-r<0) return 0;
    return 1;
}

int main(){
#ifndef ONLINE_JUDGE
    FIN
#endif

    scanf("%d%d",&n,&m);
    for(int i=0;i<n;i++){
        scanf("%s",str[i]);
    }

    for(int i=0;i<n;i++){
        for(int j=0;j<m;j++){
            int cnt=0;
            if(str[i][j]=='*'){
                for(int a=1; ;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] = 1;  //求十字架的长度
                            vis[i][j] = 1;
                        }else break;
                    }else break;
                }
            }
            if (cnt != 0) 
                v.push_back(node{i+1, j+1, cnt});
        }
    }

    bool ok = 1;
    for (int i = 0; i < n; i++){
        for (int j = 0; j < m; j++){
            if (str[i][j] == '*' && !vis[i][j]){
                ok = 0;
                break;
            }
        }
    }

   if (!ok){
        printf("-1\n");
        
    }else{
        printf("%d\n", v.size());
        for (int i = 0; i < v.size(); i++){
            printf("%d %d %d\n", v[i].x, v[i].y, v[i].cnt);
        }
    }

}
View Code

 

相关文章: