java 最低列车平台调度
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了java 最低列车平台调度相关的知识,希望对你有一定的参考价值。
import java.util.*;
public class MinTrainPlatforms {
public static void main(String args[]) {
MinTrainPlatforms minTrainPlatforms = new MinTrainPlatforms();
int[][] arrival = {
null,
{},
{1},
{2,3,5,7,9},
{2,3,4,5},
{200,210,300,320,350,500}
};
int[][] departure = {
null,
{},
{3},
{9,4,6,8,10},
{9,7,5,11},
{230,320,340,400,430,520}
};
for(int i=0; i< arrival.length; i++) {
System.out.println("Input: " + Arrays.toString(arrival[i]) + " " + Arrays.toString(departure[i]) +
" Result: " + minTrainPlatforms.find(arrival[i], departure[i]));
}
}
private int find(int[] arrival, int[] departure) {
if(arrival == null || departure == null ||
arrival.length != departure.length || arrival.length < 1) {
return 0;
}
Arrays.sort(arrival);
Arrays.sort(departure);
int platforms = 0;
int depatureIndex = 0;
int maxPlatforms = 0;
for(int i=0; i< arrival.length;i++) {
if(arrival[i] < departure[depatureIndex]) {
platforms++;
} else {
platforms--;
depatureIndex++;
}
maxPlatforms = Math.max(platforms, maxPlatforms);
}
return maxPlatforms;
}
}
以上是关于java 最低列车平台调度的主要内容,如果未能解决你的问题,请参考以下文章
L2-014. 列车调度
L2-014. 列车调度
noip模拟赛 列车调度
L2-014. 列车调度
列车调度(队列实现)
7-2 列车调度 (25 分)