求发个题解

只过了38%,求Java解。相对于C++\C,java更容易造成程序运行超时。
importjava.util.Scanner;
 
publicclassMain {
 
    publicstaticvoidmain(String[] args) {
        Scanner in = newScanner(System.in);
        intN = in.nextInt();
        intM = in.nextInt();
        intQ = in.nextInt();
        String str = "";
        char[][] arrs = newchar[N][M];
        for(inti = 0; i < N; i++) {
            str = in.next();
            arrs[i] = str.toCharArray();
        }
        while(Q-- > 0) {
            intx = in.nextInt();
            x = x - 1;
            inty = in.nextInt();
            y = y - 1;
            String p = in.next();
            charps = p.charAt(0);
            booleanfind = false;
            switch(ps) {
            case'L':
                for(inti = y; i >= 0; i--) {
                    if(arrs[x][i] == '#') {
                        find = true;
                        break;
                    }
                }
                break;
            case'R':
                for(inti = y; i < M; i++) {
                    if(arrs[x][i] == '#') {
                        find = true;
                        break;
                    }
                }
                break;
            case'U':
                for(inti = x; i >= 0; i--) {
                    if(arrs[i][y] == '#') {
                        find = true;
                        break;
                    }
                }
                break;
            case'D':
                for(inti = x; i < N; i++) {
                    if(arrs[i][y] == '#') {
                        find = true;
                        break;
                    }
                }
                break;
            }
            if(find) {
                System.out.println("NO");
            } else{
                System.out.println("YES");
            }
        }
    }
}
全部评论
暴力显然TLE= =
点赞 回复 分享
发布于 2019-02-24 09:39

相关推荐

面试摇了我吧:啊哈哈面试提前五个小时发,点击不能参加就是放弃
点赞 评论 收藏
分享
牛客771574427号:恭喜你,华杰
点赞 评论 收藏
分享
点赞 收藏 评论
分享
牛客网
牛客企业服务