java 0分,全部测试点RE,下载用例跑完正确,何解

P1825 [USACO11OPEN] Corn Maze S

[测试点数据](https://www.luogu.com.cn/record/102135055) ``` 用例#1 5 6 ###=## #.W.## #.#### #.@W## ###### 输出 3 ``` 完全正确,但是跑洛谷判定全部RE
by XieLee @ 2023-02-14 17:19:11


输入的问题 不要直接用`bf.readLine()` 我给你改了一下输入,94分 ```java import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.IOException; import java.io.InputStreamReader; import java.io.OutputStreamWriter; import java.io.PrintWriter; import java.io.StreamTokenizer; import java.util.ArrayDeque; import java.util.Queue; public class Main { static BufferedReader bf=new BufferedReader(new InputStreamReader(System.in)); static StreamTokenizer st =new StreamTokenizer(bf); static int X; static int Y; static PrintWriter pw =new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out))); static char[][]a; static boolean[][]vis; static int []dx= {1,0,-1,0}; static int []dy= {0,1,0,-1}; static int sx,sy; static Queue<Node>que=new ArrayDeque<>(); public static String nextLine() throws IOException{ String line = bf.readLine(); while(line.length()==0) line = bf.readLine(); return line; } public static void main(String[] args) throws IOException { X=nextInt(); Y=nextInt(); a=new char[X][Y]; vis=new boolean[X][Y]; for(int i=0;i<X;i++) { String s=nextLine(); for(int j=0;j<s.length();j++) { a[i][j]=s.charAt(j); if(a[i][j]=='@') { sx=i;sy=j; } } } que.add(new Node(sx,sy,0)); run(); pw.flush(); } private static void run() { while(!que.isEmpty()) { Node node=que.peek(); que.remove(); if(a[node.x][node.y]=='=') { pw.print(node.t); return; } if(a[node.x][node.y]>='A'&&a[node.x][node.y]<='Z') { node=go_anther(node.x,node.y,node.t); } for(int i=0;i<=3;i++) { int nx=node.x+dx[i]; int ny=node.y+dy[i]; if(nx>=0&&nx<X&&ny>=0&&ny<Y&&a[nx][ny]!='#'&&!vis[nx][ny]) { vis[nx][ny]=true; que.add(new Node(nx,ny,node.t+1)); } } } } private static Node go_anther(int nx, int ny, int t) { for(int i=0;i<X;i++) { for(int j=0;j<Y;j++) { if(a[i][j]==a[nx][ny]&&(i!=nx||j!=ny)) { return new Node(i,j,t); } } } return null; } static int nextInt() throws IOException { st.nextToken(); return (int)st.nval; } } class Node{ int x; int y; int t; public Node(int x, int y, int t) { super(); this.x = x; this.y = y; this.t = t; } public int getX() { return x; } public void setX(int x) { this.x = x; } public int getY(){ return y; } public void setY(int y){ this.y = y; } public int getT() { return t; } public void setT(int t) { this.t = t; } } ```
by KKKZOZ @ 2023-02-14 17:46:18


|