Untitled

 avatar
Darin
plain_text
a year ago
1.5 kB
1
Indexable
Never
int move(int mNum) {
		int sum = 0;
		PriorityQueue<Passenger> PQ;
		Passenger[][] Pmax = new Passenger[numS - 1][mNum];
		Passenger[][] Pmin = new Passenger[numS - 1][mNum];
		for (int i = 0; i < numS - 1; i++) {
			PQ = new PriorityQueue<Passenger>(new minFirst());
			PQ.addAll(arrQueue.get(i));
			arrQueue.remove(i);
			arrQueue.add(i, PQ);
		}
		for (int i = 0; i < numS - 1; i++) {
			for (int k = 0; k < mNum; k++) {
				Pmin[i][k] = arrQueue.get(i).poll();
			}
		}
		for (int i = 1; i < numS; i++) {
			PQ = new PriorityQueue<Passenger>(new maxFirst());
			PQ.addAll(arrQueue.get(i));
			arrQueue.remove(i);
			arrQueue.add(i, PQ);
		}
		for (int i = 0; i < numS - 1; i++) {
			for (int k = 0; k < mNum; k++) {
				Pmax[i][k] = arrQueue.get(i + 1).poll();
			}
		}
		for (int i = 0; i <= numS - 2; i++) {
			for (int k = 0; k < mNum; k++) {
				arrQueue.get(i).add(Pmax[i][k]);
				arrQueue.get(i + 1).add(Pmin[i][k]);
				sum = sum + Pmin[i][k].point + Pmax[i][k].point;
			}
		}
		return sum;
	}

	class minFirst implements Comparator<Passenger> {
		public int compare(Passenger a, Passenger b) {
			if (a.point == b.point)
				return b.id - a.id;
			else
				return a.point - b.point;
		}

	}

	class maxFirst implements Comparator<Passenger> {
		public int compare(Passenger a, Passenger b) {
			if (a.point == b.point)
				return a.id - b.id;
			else
				return b.point - a.point;
		}
	}