滴滴出行918编程

诡异的一个包乱入,导致题目从100分到0分。。。我擦


package didi;

import java.io.BufferedInputStream;
import java.util.Scanner;

<span style="color:#ff0000;">import sword.stack2que;</span>

public class T1 {
	public static int[][] dir = {{1,0,0},{0,1,1},{-1,0,3},{0,-1,1}};
	public static int n = 0;
	public static int m = 0;
	public static int p = 0;
	public static int[][] min = new int[2][300];
	public static int[][] curr = new int[2][300];
	public static int mintime = Integer.MAX_VALUE;
	public static int currtime = 0;
	public static int steps = 0;
	public static int beststeps = 0;
	public static void main(String[] args) {
		Scanner scanner = new Scanner(new BufferedInputStream(System.in));
		n = scanner.nextInt();
		m = scanner.nextInt();
		p = scanner.nextInt();
		int[][] maze = new int[n][m];
		for(int i = 0 ; i < n ; i++){
			for(int j = 0 ; j < m ;j++){
				maze[i][j] = scanner.nextInt();
			}
		}
		maze[0][0]=0;
		go(0, 0, maze);
//		System.out.println(cango(1, 0, 0, 1, maze));
		if(mintime==Integer.MAX_VALUE)System.out.println("Can not escape!");
		else {System.out.print("["+min[0][0]+","+min[1][0]+"]");
			for(int i = 1 ; i< beststeps ; i++){
				System.out.print(",["+min[0][i]+","+min[1][i]+"]");
			}
			System.out.print(",["+0+","+(m-1)+"]");
		}
	}
	public static void go(int a,int b,int[][] maze){
		if(a==0&&b==m-1){
			if(p>=currtime){
				if(currtime<mintime){
					mintime = currtime;
					min=curr.clone();
					beststeps = steps;
				}
			}
		}
		for(int i = 0 ; i < 4 ; i++){
//			System.out.println(cango(a, b, dir[i][0], dir[i][1], maze)+"             "+p);
			if(cango(a, b, dir[i][0], dir[i][1], maze)){
				steps++;
				curr[0][steps]=a+dir[i][0];
				curr[1][steps]=b+dir[i][1];
				currtime+=dir[i][2];
//				System.out.println(curr[0][steps]+"                 "+curr[1][steps]+"             "+currtime);
				maze[a+dir[i][0]][b+dir[i][1]]=0;
				go(a+dir[i][0], b+dir[i][1], maze);
				maze[a+dir[i][0]][b+dir[i][1]]=1;
				currtime-=dir[i][2];
				steps--;
			}
		}
	}
	public static boolean cango(int i,int j,int a,int b,int[][] maze){
		if(i+a>=0&&i+a<n&&j+b>=0&&j+b<m&&maze[i+a][j+b]==1&&p>=currtime)return true;
		return false;
	}
}



//4 4 10
//1 0 0 1
//1 1 0 1
//0 1 1 1
//0 0 1 1


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值