zoukankan      html  css  js  c++  java
  • codeforces 1015E1&&E2

    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 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 nmn⋅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 nmn⋅m stars.

    Input

    The first line of the input contains two integers nn and mm (3n,m1003≤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 (0knm0≤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 = 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
    ");
            
        }else{
            printf("%d
    ", v.size());
            for (int i = 0; i < v.size(); i++){
                printf("%d %d %d
    ", v[i].x, v[i].y, v[i].cnt);
            }
        }
    
    }
    View Code
    每一个不曾刷题的日子 都是对生命的辜负 从弱小到强大,需要一段时间的沉淀,就是现在了 ~buerdepepeqi
  • 相关阅读:
    共创力董事长杨学明先生受邀参加CED智慧大会!
    杨学明老师为华宇金信(北京)软件有限公司提供为期两天的内训服务!
    《互联网敏捷测试管理实践》课程大纲 2018.12.15~16 (上海)
    共创力咨询杨学明老师为国电南瑞提供两天的内训服务!
    《软件测试管理》深圳公开课预告 2018.11.23~24 中南海滨大酒店
    软件测试管理的十大挑战
    对于开发人员修改代码引发新问题的处理措施
    热烈庆祝杨学明老师为上海某著名金融互联网公司提供两天的内训服务!
    《高效的互联网研发项目管理》课程大纲
    《软件测试管理》北京公开课预告 2018.9.28~29
  • 原文地址:https://www.cnblogs.com/buerdepepeqi/p/9416521.html
Copyright © 2011-2022 走看看