炸弹人(广搜代码)

找最多敌人的位置

input

13 13
#############
#GG.GGG#GGG.#
###.#G#G#G#G#
#.......#..G#
#G#.###.#G#G#
#GG.GGG.#.GG#
#G#.#G#.#.#.#
##G...G.....#
#G#.#G###.#G#
#...G#GGG.GG#
#G#.#G#G#.#G#
#GG.GGG#G.GG#

#############

output

7 11

import java.util.LinkedList;
import java.util.Queue;
import java.util.Scanner;

public class 炸弹人 {
	static char[][] mp = new char[51][51];
	static int[][] book = new int[51][51];
	static int num(int i,int j){
		int sum=0;
		int x=i,y=j;
		while(mp[x][y]!='#'){
			if(mp[x][y]=='G')
				sum++;
			x--;
		}
		x=i;y=j;
		while(mp[x][y]!='#'){
			if(mp[x][y]=='G')
				sum++;
			x++;
		}
		x=i;y=j;
		while(mp[x][y]!='#'){
			if(mp[x][y]=='G')
				sum++;
			y++;
		}
		x=i;y=j;
		while(mp[x][y]!='#'){
			if(mp[x][y]=='G')
				sum++;
			y--;
		}
		return sum;
	}
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner in = new Scanner(System.in);
		Queue qe = new LinkedList();
		int m=in.nextInt();
		int n=in.nextInt();
		int max=0;
		int mx;
		int my;
		int[][] next = {{0,1},{1,0},{-1,0},{0,-1}};
		int startx=0,starty=0,tx,ty,step=0;
		
		
		for(int i=0;i=m||ty<0||ty>=n)continue;
				if(mp[tx][ty]=='.'&&book[tx][ty]==0){
					book[tx][ty]=1;
					qe.add(new note(tx,ty));
					num(tx,ty);
					if(max

你可能感兴趣的:(2018,蓝桥杯)