测试点4 runtime erro 好累啊 麻了
  • 板块P1363 幻象迷宫
  • 楼主fldfld
  • 当前回复3
  • 已保存回复3
  • 发布时间2022/8/1 13:55
  • 上次更新2023/10/27 17:31:17
查看原帖
测试点4 runtime erro 好累啊 麻了
345765
fldfld楼主2022/8/1 13:55
import java.io.IOException;
import java.util.*;
import java.io.*;
public class Main {
    static int n;
    static int m;
    static BufferedReader in =new BufferedReader(new InputStreamReader(System.in));
    static StreamTokenizer st =new StreamTokenizer(in);
    static boolean res =true;
    public static int nextInt() throws IOException {
        st.nextToken();
        return (int)st.nval;
    }
    static char[][] cs;
    static int [][] directions = {{1,0},{-1,0},{0,1},{0,-1}};
    static Scanner scan = new Scanner(System.in);
    static HashSet<Integer> set = new HashSet<>();
    static HashSet<Integer> isvisited = new HashSet<>();
    static boolean[][]  isviisted= new boolean[100][100];
    public static void main(String[] args) throws IOException {
      String line ;
      while(scan.hasNext()) {
          // String strs[] = line.split(" ");
          // n = Integer.parseInt(strs[0]);
          // m = Integer.parseInt(strs[1]);
          n = scan.nextInt();
          m = scan.nextInt();
          cs = new char[n][m];
          scan.nextLine();
          isviisted = new boolean[n][m];
          for (int i = 0; i < n; i++) {
              String strs2 = scan.nextLine();
              cs[i] = strs2.toCharArray();
          }
      
          int x = -1;
          int y = -1;
         for(int i = 0;i<n;i++){
             for(int j  = 0;j<m;j++){
                 if(cs[i][j]== 'S'){
                     x = i;
                     y = j;
                 }
             }
         }
          dfs(x,y,x,y);
         if(res){
           System.out.println("No");
         }else{
             System.out.println("Yes");
         }
   
          res = true;
          isvisited.clear();
          set.clear();
      }

//  for(int i  = 0;i<n;i++){
//      if(cs[i][0] == '.'){
//
//      }
//      if(cs[i][m-1] == '.'){
//
//      }
//  }
//  for(int i =0;i<m;i++){
//      if(cs[0][i] == '.'){
//
//      }
//      if(cs[0][i] == '.'){
//
//      }
//  }

         ///



    }
    public static void dfs(int x, int y,int lx, int ly){
         // isviisted[x][y] =true;
            // System.out.println(x+" "+ y+" "+lx+" "+ly);
       if(set.contains(lx+ly*10000)==true && isvisited.contains(x+y*10000)!=true){
         
              res = false;
           return;
        }
        isvisited.add(x+y*10000);
        set.add(lx +ly*10000);
        
        for(int [] dir: directions){
            int nx = x + dir[0];
            int ny = y + dir[1];
            int mx= (lx+dir[0]+n)%(n);
            int my = (ly+dir[1]+m)%(m);
            if(cs[mx][my] != '#' && (isvisited.contains(nx+ny*10000)!=true ||set.contains(mx+my*10000) != true )){
                dfs(nx,ny,mx,my);
            }
        }
    }

}

6 6 ##...# .##..# ..#.S. ..#.#. ..###. ...#.. 12 12 ##.#######.# #..#......S# #.#..####### ..#.###..... ##..##..#### #..##..##### ..##..#..... ###..##.#### ##..#...#### #..##.###### ..##..####.. ##...#####.# 12 12 ###.#.##.#.# ....#.##...# .####.###### .####.###### .####.###### .####.###### .#....###### .#.##.###### .#.##.##S... ##.##.##.### ...##.##.#.. ###...##.#.# 12 12 ######.#.#.# ######.#..S# .......####. ######.####. ............ ############ .....#...... ####.#.##### .....#...... ############ .........#.. ########.#.# 12 12 ######.#.#.# ######.#...# .......####. ######.####. ............ ############ .....#...S.. ####.#.##### .....#...... ############ .........#.. ########.#.# 100 100 ....#.....#...##.....##.##...............###.##....##..##...##........#..#..#.#...#......#.#...#..#. .##....#..#.#..#..#........##...#...##.....#...#.###.#....#...#..##..#.......#...###....##...#...... ..#...#.#....#....#.............#.###....##.......#............#...#........###....#.#..#.....#.#..# ..#..#.........#...#.##.#......#..........#.....#..#...#.#..#...#..#..#..#..........##.#..........## ....#..#................#.#.....##...#......##...#.....................#...#.#.#.......##.......#... ......#.#.#.#.......#.........#..#......#....#..#.......#.#.#..##.#...####....#..#......##.....###.# ..#....#.....#....#...........#.#..####....#.#.......S.........##.#.#...#.#.#..#.....#...#...#...##. ##..#.##.#...#.....##..#..........#...#.......#...#.....#....##.........#...#...#........#.#........ ...#.#.......##.##...#..##........##.....#.#......##...##......#.....#..#.#......#..#............#.# ....#..#....#.#.........#......##............#.....#....##.......#.........#..............##......#. .....#.....#......##.#.#..##.#.#........#...##..#.#...#...........#.#.#....##....#..#..#..##....#... ..............#....#.....#.#..#..#.#...#..#..#.#.......#...#....#....##..........#.#.#..##.......... ##......#...##.#..#........#.#..##..##.#.#.##.......#..#.##.#..#.##.....#.##..###....##..###...#.#.# .#.........#.#............#..#....##..#...#.......#...##............#..#.#.#..#..#.#.##..##...#....# .......#..#.##.......#.....#..#.####....#.....#..##......#....#.#...##.#...#.......#..#...#.#....#.. ...#.##...#..#.##.#.........#####....#.#.......##.#..#.#............#............##....##.......#... ......#......#.#.#....#.....####...#.#....#..#............#.##..........#..#...............#.......# ....#......#.#..........##...##.#....#.##.....#.#.#..#...#..#...............#...#.....#......#..#... .#....###.###.#..#..#.......##....##..#..#............#.#....#...#.#.....#..##..#......#.#...#....#. ...#.#..##.##.....#.#............#...#..#......#.#....#....#...#....##.....#.##.##..#...#......##... .#.#.###.#.....#.#....#................#..#..#..##.....##.............##.....#...#.#..####.#..#.#.## .#..#..##...##.....#......#...#....#.......#.#.#.#...####.............#....#.##..###..#.....#..##.#. ..##...#.....#.......#.#.#..........##.....##......##..#.........###..#.#.##.#.......#...##..#.#.##. ..#..##......#..#...........#....#.#...#...#.#..##..##....#...#...###..#....#..#####...#..#######.## .#...#....##..#...##...#...#..........#...#.###......#..##.#....####.............#....#.....##...... #......#.#...........##...##...#..........##.......#....#.......#.#...##......#.#..#..###...#.#..... .#........##.#.#....#.......##.#.#....#....#...........#.###.#..#.......#...#...###.##...#..#.#...## ...............#.#........#..###....##.....#....##..#...#......#..#....#...#.##.....#..###.....###.. ...#...#...........#.#...#......#........##...#...#..##.#.#.#....#......#........#....#.#.#.#.....#. ..#.##.....#.....#.#.#..#..###.......#........#...#...........#..##...#.#.#.........#...#....#...... #.#.#....#####..##.#.............#.###.#..##.....#......#...##.#.#...###.....##...#.#..#...........# ......#.#........#....##........#..#....#..#..#..#.#....##........##....##..#.......#.........#...#. ..............#.##.....#....#.##.....#.#....#....#...#..##..#..##...###.#..#.....#..........#...#..# .#.#.........##....#.......#...#.....#...##..#..#..##......#..##........#..#.#....#................. ................##.....#.....#........#...##.#.........#.......#.......##..#...##.....#.#...#......# ##..##...##.....#.##..#.....#..#....#......#.......#..........##..#.#.......#...#.....#.#...#..#.### ##.#.....#.#....#..##...#..#...##.##...#.#.##....#.##..#.#.......#....#...####.#.....#..##..#..#.... #......##...#...#......##..#....#....##......#..#.......##...#...#......#.#....#......##.#.#..#.###. #.....#.##...##........#...#.#..##........#....#..#.##....##..##....##...#.........#.#.###...#.#.#.. ...#...#.#.........###.....###...###..###............#......#........#.#........#.##................ .#..###..##....#.#...#......#.#.#.....#..#....#.###.#.#.#..#..#........#..####......#.#....#....#... .........#...............##......#.........#..##......#.#.......#..##...##..#.#..#.........#..#...#. ...................#.......#.#.......#.#......#........##.##....#..#..#.##........#.#.#..#.......... ........#.###....#..##..###.#.....#..##...#....#.#......#.#...#..#..........#.#....#................ .#..###.........##....#...#.....#..###..#...#..#...#..##.#...#.#..##.....#...##..#.#...#...#....##.. ....#.#............#.......#.#....##.#..#.#.##........#.....#....#..#...........#...###..#.......##. .#.##......#.#..........#.#......##...#..#.#..###.#.##....##........#.#.#.#.....#.#.#.###..#........ ..##....#.##...#.##......#.#....#..#..##.........#....##.....#...#....#...........#..#..........#.#. ......#.......#..#.#....#..#......#..#.###.#....#..#..#.......#.#....####..#...#................#..# #..#.#.......#..#..##.........#..........##.#.#...#.#.##...#...#..#.#..#.#...#...#..............##.. #.#.......#...#..#..#......#.#....##.#..##......##...................#.#.......##.#.##..........#.#. ...#......#........#..##....#.....#........#....#........#...#..#...#.##......###.##..##.#.......... #...........#..#......#..#........#....##.......#.........#.#....#..##....#.#..###....#..#...##..#.. ......#....##.#..#...##.#.#.........#.#.#.#......#..#..##.##.#..###..#...#.#....#.........####..#... ##.#...#.#....#.##.#.#..##..#.#......#....#......#.....#.....#.##.....##..#.#...#...#......##......# .#.##.#....#..##.......##...#....#..........#........#....#..............##.....#......#.#..#....... .##....#..........#...#.....#.####.....#.##.#....#...##......#.............#......##.#..#...#....... ..#....#.....#..##.........#..............#.#......#....#.#......####.......#....##................# .#....#.##..#....#.......##.........#.....#.....#..#........#........#.....#..#.#........#.........# ......##.##...#####.#................#..#.....#..#.#......#.#...#....#......#....#.#.#......##...... #.......###...........#.......#........#.#....#...#..#...........#..#..................#..#.#.#..##. ..#.#........#..#.#....#....##...##.##.......#..#.#..#.........###....#......#.###..#....#....##..## .#..#....#........##......##..#..###.#####..#..#....#..####..#...#.......##.#.#................#.... .####...#.....##..##.#..#..#.#.........#..####...#..#....##.#....#....#....#.#...###....#.#......#.. ####.#..#...#........#.###.#...#..#.......#......#..#....#...#......##..##..#......#....#...#..###.. ...#...........###....#..#..........##.##....#.....##.....#..##.#.#..#...#..##..##....#.....#......# #.....##....#.#.#..#..........#....##..##.#...#.....#.#......###.#.....#..#..#............#......... ....#.#......#.##...#..#.......#.#.......#...#.....#####..........#............##.##.#.....#.#..#.#. ..##...............##...#.....##.#..###.#..............##.#.....##.##...#.....#.............#......# .##..#.........#......##..#.....#..#........#.#.........##..##...#....#..#..##..#.........#...#.#.## ......###.#.#......##..#......#...#...#.#.#..#...#...#..#.#.#.#.....#........#.#.#.#.....#..##.##... ...#.#.#..###............#..#...#.....##..#..........#....#....#........#....#.##.###........#..#.#. ..#...###..#......#...#.....#..##.....#..#.#..#..........#.##..##..#.......#.....##.#...#..#....#... #...##.#...#.#..#....##.#..#..........#.#...##..#..........#.#.....#......#.#.......#...#......##... ..##..#.......#....#.###.................#....#......#.#...###.#....#....#...#.#.....##.....#..#.... .##...........##...##..........#.......#..#..##..#.#...##....#...###.............#.....#......#.#... .#..#....##.......#..#.#.##..#.....#....#.#..#..#..##........#....#.###....##..#..#....##........#.. #.#.#.#..##..........#........#.....#...#....#...#..#.###....#.......#....###...#...#....#.#.....#.. .#..#......#.#.#.##....#......#....#.....##..##..#.##....#..#.#...#.....#..#.###.......#..#.....#.#. .....###.....####..##..#..#.#...........#.#.#...#...#.##......#.#....#..#.#.##.....#.#...........### ...#...#..#....#.#...#.........##......#.....##......###..#...##.###....###.#......#.#....##....#... ....#...##..##.....#..........#..#.#.......#.##..#..#.#.....#........#..#.#..#....#.#..........#.#.. ..##.......#...#.#......#.........#....##.#...#....##......#....##..#.....###.#......#.##.#.....#.#. .#...##.#........#.....#.....###..#.#.......##.#.#.#..##...#.#..#....#.....................#..#..... ...#..#.#..#..#..#.....#..#..........##.#.......#....###.......#....#..........#.....#.........###.. ...##....##..#...#.#...........#...#...######...#.....#........#..###..#.....#..##...#.......#...##. ...#..............##...#.#......#..#.....#.##.#..#....#.......#.#.......#..........#......#.#.##.... ##.....#......#.###...#.....#..#.....#.#....#..#...#..#..#....#.#..#..#...#........#.......#..#..... #........##.#...#...........#..##.#.....#.........###.....##.........#..........##....#####......... #....#...#...#...##.#...##........#...#..#.....#..##..........#.#........####........#....#......... ...#.....#.......#...#....#..#.#.#......................#..#......#...#.#.....##........#.....##.... ......#....#...#.##.##....#........#.#.............##...#.....#.#.......#...##.##...#...#..#......## ##...#.#......#.#.#.....#..#.#........#...####..#...#.......#.....#.###..#..#...#.#.......#..#...... .#......#.#.....#.#...#.....###.##..##...##......##....###..##.....##...#.##.#.##...#..#.#...#...... ...#..##..###.#.....#..#....#...##............#.#...##.........#..#....#.......##.#.##...##...##..#. .#.#.#...#...........#.......#......#.##...##.#...##..#.#.#...........##..##.####..#......#......... ..#...#.#...#.#.#........##.#.#.....#..#.#...#..##............#.....#.......#...#..#.....#...#..###. .#..##......#.##...#.##.##.#.#..#.#......#..##......#..#..........##....#...#.#.#..#..###.....#.##.. ......#..#.........#..........##..##.......#....#..##.......#........#........#..............#....#. .....#...###..#...#..##.##..###.#.#...#......#....#........##..#........##.#..#...#.##.#.#...##..... Yes Yes Yes Yes No Yes 本地又能运行?

2022/8/1 13:55
加载中...