博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
CSP 2016_4_4 游戏
阅读量:4215 次
发布时间:2019-05-26

本文共 1654 字,大约阅读时间需要 5 分钟。

import java.util.LinkedList;import java.util.Queue;import java.util.Scanner;public class Main {	int n, m, t;	Node [][]map;	int [][]start;	int [][]end;	int[][][]flag;	int [][]dir = {
{1,0},{-1,0},{0,1},{0,-1}}; Queue
que; public static void main(String[] args) { new Main().run(); } public void run(){ Scanner in = new Scanner(System.in); que = new LinkedList<>(); int n = in.nextInt(); int m = in.nextInt(); int t = in.nextInt(); map = new Node[n+1][m+1]; for(int i = 1; i <= n; i++){ for(int j = 1; j <= m; j++ ){ map[i][j] = new Node(i, j, 0); } } flag = new int[102][102][305]; start = new int[n+1][m+1]; end = new int[n+1][m+1]; for(int i = 0; i < t; i++ ){ int x = in.nextInt(); int y = in.nextInt(); int a = in.nextInt(); int b = in.nextInt(); start[x][y] = a; end[x][y] = b; } flag[1][1][0] = 1; que.offer(map[1][1]); while(!que.isEmpty()){ Node node = que.poll(); if(node.x == n && node.y == m){ System.out.println(node.step); break; } for(int i = 0; i < 4; i++ ){ int xx = node.x + dir[i][0]; int yy = node.y + dir[i][1]; int step = node.step + 1; if(step > 300) break;// if(xx == n && yy == m){// System.out.println(step);// tag = 0;// break;// }// if(tag == 0)// break; if(flag[xx][yy][step] == 0 && (xx>0&&yy>0&&xx<=n&&yy<=m)&&(step < start[xx][yy] || step > end[xx][yy])){ flag[xx][yy][step] = 1; que.offer(new Node(xx, yy, step)); } } } }}class Node{ int x, y; int step; public Node(int x, int y, int step){ this.x = x; this.y = y; this.step = step; } }

flag三维数组 表示此位置此时刻不能同时被入队

此外:注释的部分不对 也不知道为啥。。。理论上一样的

转载地址:http://nlimi.baihongyu.com/

你可能感兴趣的文章
Python学习笔记——运维和Shell
查看>>
Python学习笔记——nginx
查看>>
Python学习笔记——自动化部署
查看>>
Python学习笔记——多任务-协程
查看>>
Python学习笔记——WSGI、mini-web框架
查看>>
Python学习笔记——闭包、装饰器
查看>>
Python学习笔记——mini-web框架 添加路由、MySQL功能
查看>>
Python学习笔记——mini-web框架 添加log日志、路由支持正则
查看>>
Python学习笔记——元类、实现ORM
查看>>
Python学习笔记——Celery
查看>>
Python学习笔记——数据分析之Matplotlib绘图
查看>>
Python学习笔记——数据分析之工作环境准备及数据分析建模理论基础
查看>>
Python学习笔记——数据分析之Seaborn绘图
查看>>
Python学习笔记——数据分析之Bokeh绘图
查看>>
Python学习笔记——数据分析之数据可视化工具实战案例:世界高峰数据可视化
查看>>
Python学习笔记——科学计算工具Numpy
查看>>
Python学习笔记——数据分析之数据分析工具Pandas
查看>>
Python学习笔记——Pygame之基础知识
查看>>
Ubuntu 18.04双系统安装教程-超详细(原系统Win7,解决安装完成后启动Ubuntu进入GLUB的问题)
查看>>
Web前端学习笔记——构建前端自动化工作流环境
查看>>