社区讨论

P1518 我用java在idea中可以得出答案,洛谷中WA

学术版参与者 2已保存回复 3

讨论操作

快速查看讨论及其快照的属性,并进行相关操作。

当前回复
3 条
当前快照
1 份
快照标识符
@lob5ya10
此快照首次捕获于
2023/10/29 15:42
2 年前
此快照最后确认于
2023/11/03 22:00
2 年前
查看原帖
JAVA
import java.io.*;

public class Main {
    static char[][] chars = new char[10][10];
    static int rx = 0,ry = 0;
    static int nx = 0,ny = 0;
    static int lt = 0;
    static int rlt = 0;
    static int[] ints = {-1,0,0,1,1,0,0,-1};

    static BufferedReader ins = new BufferedReader(new InputStreamReader(System.in));
    static StreamTokenizer in = new StreamTokenizer(ins);
    static PrintWriter out = new PrintWriter(new OutputStreamWriter(System.out));

    public static void main(String[] args) throws IOException{
        char ct;
        for(int i = 0;i<10;i++)
        {
            for(int i1 = 0;i1<10;i1++)
            {
                ct = (char)ins.read();
                if(ct!='\n')
                {
                    chars[i][i1] = ct;
                    if(ct == 'C')
                    {
                        nx = i;
                        ny = i1;
                    }
                    else if (ct == 'F')
                    {
                        rx = i;
                        ry = i1;
                    }
                }
                else
                {
                    i1--;
                }
            }
        }
        int count = 0;
        while(rx!=nx||ry!=ny)
        {
            nYD();
            rYD();
            count++;
            if(count > 1000)
            {
                out.print(0);
                out.close();
                System.exit(0);
            }
        }
        out.println(count);
        out.close();
    }

    public static void nYD()
    {
        while(true)
        {
            if(nx+ints[lt]>=0&&nx+ints[lt]<10&&ny+ints[lt+1]>=0&&ny+ints[lt+1]<10&&chars[nx+ints[lt]][ny+ints[lt+1]]!='*')
            {
                nx += ints[lt];
                ny += ints[lt+1];
                break;
            }
            else
            {
                lt+=2;
                lt%=8;
                break;
            }
        }
    }

    public static void rYD()
    {
        while(true)
        {
            if(rx+ints[rlt]>=0&&rx+ints[rlt]<10&&ry+ints[rlt+1]>=0&&ry+ints[rlt+1]<10&&chars[rx+ints[rlt]][ry+ints[rlt+1]]!='*')
            {
                rx += ints[rlt];
                ry += ints[rlt+1];
                break;
            }
            else
            {
                rlt+=2;
                rlt%=8;
                break;
            }
        }
    }
}

回复

3 条回复,欢迎继续交流。

正在加载回复...