求发个题解

只过了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

相关推荐

把球:这个听过,你加了就会发现是字节的hr
点赞 评论 收藏
分享
dongsheng66:如果想进大厂的话,在校经历没必要占这么大篇幅,可以把专业技能单独放一个专栏写,可以加个项目经历
点赞 评论 收藏
分享
评论
点赞
收藏
分享
牛客网
牛客企业服务