啊。滴滴本地通过最后时刻在线不通过。

颜后最后一题没做。啊,牛客网环境比其他的强。
import java.util.*;
public class Main { public static void main(String[] args) {
        Main main = new Main();
        Scanner sc = new Scanner(System.in); while(sc.hasNext()){
            Stack<Integer> stack = new Stack<Integer>(); int n = sc.nextInt(); int m = sc.nextInt(); int p = sc.nextInt(); int[][] target = new int[n][m]; int[][] result = new int[n][m]; for(int i=0;i<n;i++){ for(int j=0;j<m;j++){
                    target[i][j] = sc.nextInt();
                }
            }
            result[0][0] =p;
            stack.push(0);
            stack.push(0); int i=0; int j =0; while(i<n-1&&j<m-1) { //水平第一行  if (i==0) { if (target[i][j + 1] != 0) {
                        result[i][j + 1] = result[i][j] - 1;
                        stack.push(i);
                        stack.push(++j); if(result[i][j]<0){
                            System.out.println("Can not escape!");
                        } continue;
                    } else if (target[i + 1][j] != 0) {
                        result[i + 1][j] = result[i][j];
                        stack.push(++i);
                        stack.push(j); if(result[i][j]<0){
                            System.out.println("Can not escape!");
                        } continue;
                    }else {
                        j=stack.pop();
                        i=stack.pop(); continue;
                    }
                } //除掉水平垂直  if(i!=0&&j!=0){ //向右  if (target[i][j + 1] != 0) {
                        result[i][j + 1] = result[i][j] - 1;
                        stack.push(i);
                        stack.push(++j); if(result[i][j]<0){
                            System.out.println("Can not escape!");
                        } continue;
                    } //向上  if (target[i-1][j]!=0){
                        result[i-1][j] = result[i][j]-3;
                        stack.push(--i);
                        stack.push(j); if(result[i][j]<0){
                            System.out.println("Can not escape!");
                        } continue;
                    } //向下  if (target[i + 1][j] != 0) {
                        result[i + 1][j] = result[i][j];
                        stack.push(++i);
                        stack.push(j); if(result[i][j]<0){
                            System.out.println("Can not escape!");
                        } continue;
                    } //向左  if (result[i][j-1]==0&&target[i][j-1]!=0){
                        result[i][j-1]=result[i][j]-1;
                        stack.push(i);
                        stack.push(--j); if(result[i][j]<0){
                            System.out.println("Can not escape!");
                        } continue;
                    } //弹出  else {
                        j=stack.pop();
                        i=stack.pop(); continue;
                    }
                } if(i!=0&&j==0){ //向右  if (target[i][j + 1] != 0) {
                        result[i][j + 1] = result[i][j] - 1;
                        stack.push(i);
                        stack.push(++j); if(result[i][j]<0){
                            System.out.println("Can not escape!");
                        } continue;
                    } //向下  if (target[i + 1][j] != 0) {
                        result[i + 1][j] = result[i][j];
                        stack.push(++i);
                        stack.push(j); if(result[i][j]<0){
                            System.out.println("Can not escape!");
                        } continue;
                    } //弹出  else {
                        j=stack.pop();
                        i=stack.pop(); continue;
                    }
                }
            } if(j==m-1){ //shang  for(int k=j;k>0;k--){ if(target[i][k]==0){
                        System.out.println("Can not escape!");
                    }else {
                        result[i-1][j] = result[i][j]-3;
                        stack.push(--i);
                        stack.push(j); if(result[i][j]<0){
                            System.out.println("Can not escape!");
                        } continue;
                    }
                }
            }
            Stack<Integer> stack1 = new Stack<Integer>(); while (!stack.isEmpty()){
                stack1.push(stack.pop());
            } while (!stack1.isEmpty()){
                System.out.print("[");
                System.out.print(stack1.pop());
                System.out.print(",");
                System.out.print(stack1.pop());
                System.out.print("]"); if(!stack1.isEmpty())
                System.out.print(",");
            }
            System.out.println();
        }
    }
}
纪念一下#滴滴#
全部评论
我觉得是我的代码can not escape没有输对,我也是最后几分钟提交
点赞 回复 分享
发布于 2016-09-18 17:44
再给我一分钟我就ac了啊!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
点赞 回复 分享
发布于 2016-09-18 17:22
我做对了,多输出一行
点赞 回复 分享
发布于 2016-09-18 17:10

相关推荐

头像
04-27 15:11
已编辑
华东师范大学 算法工程师
暑期实习从2月开始投,面了两个月,流程该挂的都挂完了,腾讯字节一共号称是1.7w个hc,不知道都发给谁了,估计今年秋招要难顶。Timeline米哈游、美团、蚂蚁、微软等公司直接简历挂穿,没进面。携程:3.3&nbsp;投递、测评3.12&nbsp;笔试3.18&nbsp;一面3.25&nbsp;二面4.13&nbsp;ai面(hr面)4.14&nbsp;英语测评4.23&nbsp;offer(已拒)腾讯:2.6&nbsp;测评2.28&nbsp;wxg一面3.5&nbsp;wxg二面(挂)3.11&nbsp;teg一面3.21&nbsp;teg二面(取消)3.31&nbsp;teg一面4.10&nbsp;teg二面(挂)4.21&nbsp;wxg一面4.24&nbsp;wxg二面(挂)字节:1.28&nbsp;aml约面(取消)3.17&nbsp;火山一面(挂)4.8&nbsp;aml一面(挂)4.20&nbsp;抖音data一面(挂)阿里:3.23&nbsp;投递、测评3.28&nbsp;笔试3.31&nbsp;淘天一面4.8&nbsp;钉钉一面4.9&nbsp;淘天二面4.10&nbsp;阿里控股一面4.12&nbsp;钉钉二面(取消)4.15&nbsp;淘天hr面4.16&nbsp;淘天offer(已接)4.21&nbsp;高德一面(取消)4.22&nbsp;淘宝闪购一面(取消)面试最大的感触是,现在撞上ai转型,一堆老业务急着转向,新业务非常不成熟,研究型的组bar非常高根本进不去,业务侧挂着算法的岗位干的都是工程活,面试却又要问算法,另外agent的落地也远没有那么广,绝大多数还是那套写死的系统调一下llm&nbsp;api或者做做rag,其余少部分真的在搭agent的,基本不能在线上服务用什么很智能的模型,现阶段成本太高,进去大概率就是给垃圾模型从工程方面兜底,除了业务场景的应用和数据经验以外,技术方面很难有什么提升。算法岗做不了基模的还是去搜广推好,之前判断失误了完全没投,秋招不知道还进不进得去。
嵌入式的小白:不错啊,淘天也是挺好的,恭喜
我的求职进度条
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务