Java implementation of the Blue Bridge Cup algorithm improves rectangular target

Questions algorithm improves rectangular target

Resource constraints
Time limit: 1.0s memory limit: 256.0MB
description of the problem
  in the rectangular world everything is rectangular, rectangular target gun, bullets and even rectangle. You are given an N gun target M, but to tell you the size of the bullet is (2L + 1) (2R + 1). FIG 01 is a read each point 01 indicates whether the status of each point is the center of a bullet hit (hit represents 1, not 0). Once a point is hit by a bullet in the center, then at this point Center (2l + 1) point on the range within (2r + 1) target was destroyed. Outputs the final target of the request state.
Input format
  first row N, M, L, R represents the size of the target, and the size of the bullet.
  Following a read N
M matrix 01 indicates whether the center of each dot is hit by a bullet
output format
  N * M matrix 01 indicating whether each point on the target is destroyed
sample input
. 4. 1. 1. 4
1000
0000
0000
0010
sample output
1100 is
1100 is
0111
0111
sample input
. 7. 1. 1. 4
1000
0000
0010

0000
0000
0000
0100
sample output
1100 is
1111
0111
0111
0000
1110
1110
data size and conventions
  N, M <= 600, l , r <= 5

package com.company;

import java.util.Scanner;

public class 矩形靶 {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int m = sc.nextInt();
        int l = sc.nextInt();
        int r = sc.nextInt();
        char [][] str = new char[n][m];
        char[][] a = new char[n][m];
        for (int i=0;i<n;i++){
            String s = sc.nextLine();
            if (s.equals("")){
                s=sc.nextLine();
            }
            str[i]=s.toCharArray();
            a[i]=s.toCharArray();

        sc.close();
 
        for (int i=0;i<n;i++){ 
            for (int j=0;j<m;j++){
        
                if (str[i][j]=='1'){
                    for (int i1=i-l<0?0:i-l;i1<=i+l&&i1<n;i1++){
                        for (int j1=j-r<0?0:j-r;j1<=j+r&&j1<m;j1++){
                            a[i1][j1]='1';
                        }
                    }
                }
            }
        }
        for (int i=0;i<n;i++){
            for (int j=0;j<m;j++){
                System.out.print(a[i][j]);
            }
            System.out.println();
        }
    }
}

Released 1092 original articles · won praise 5805 · Views 170,000 +

Guess you like

Origin blog.csdn.net/a1439775520/article/details/104244300