Untitled

mail@pastecode.io avatar
unknown
plain_text
a year ago
26 kB
19
Indexable
Mỏ khai thác vàng
Cho bản đồ mỏ vàng có thể được biểu diễn dưới dạng ma trận NxN

Trong bản đồ này, có một số mỏ vàng nằm ở những vị trí ngẫu nhiên (tối đa 4 mỏ trên mỗi bản đồ). Một trại sẽ được thiết lập trên bản đồ để khai thác vàng. Hàng ngày, công nhân sẽ đi từ khu trại đến địa điểm mỏ vàng. Để giảm chi phí, công ty muốn thiết lập trại sao cho khoảng cách từ trại đến địa điểm khai thác được tối ưu hóa.

Hãy xem xét bản đồ 5x5 dưới đây:



 - Công nhân không thể đi xuyên qua đá

 - Mất 1 giờ để di chuyển một ô trên bản đồ

Có hai mỏ, từ điểm xuất phát (địa điểm cắm trại), đi đến mỗi mỏ vàng phải mất 4h. Giả sử chi phí cuối cùng sẽ là chi phí cao nhất trong số đó, thì nếu chúng ta đặt trại như hình trên thì chi phí cuối cùng sẽ là 4.

Bây giờ, chúng ta xem xét ví dụ khác:



Trong ví dụ thứ 3, chi phí cuối cùng sẽ tối thiểu (1)

[ Đầu vào ]

Dòng đầu tiên nhập vào sẽ là số test case T (T ≤ 50)

Trong mỗi TC:

 - Dòng đầu tiên sẽ cho biết kích thước bản đồ N (N ≤ 20) và số lượng mỏ vàng G (2 ≤ G ≤ 4)

 - Các dòng G tiếp theo sẽ là vị trí R (hàng) & C (cột) mỏ vàng (chỉ số 1 base)

- N dòng tiếp theo sẽ là số liệu của bản đồ: 1 tượng trưng cho đường đi & mỏ vàng, 0 tượng trưng cho tảng đá (không thể đi qua)

 

[ Đầu ra ]

Chương trình của bạn sẽ đưa ra  Chi phí cuối cùng tối thiểu  để đi từ trại đến mỏ vàng.

Trường hợp 1

1

Trường hợp số 2

2

Trường hợp số 3

2

Trường hợp số 4

7

Trường hợp số 5

6

 

[ Hạn chế ]

- Bạn có thể di chuyển theo 4 hướng (lên/trái/xuống/phải)

- Bạn không thể dựng trại ở vị trí mỏ vàng hoặc đá

- Bạn có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1 1 1 1 1 1 1 1 1 
1 1 1 0 0 1 1 1 1 1 1 0 1 1 1 1 1 1 1 0 
1 1 1 1 1 1 1 0 0 1 1 1 1 1 1 1 0 1 0 0





import java.util.Scanner;

public class Solution {
	static int n, g, min, count, cnt, cnt1;
	static int[][] gold, mine, dist, gmap, tmp;
	static Queue queue = new Queue(100000);
	static int[] dx = { 1, -1, 0, 0 };
	static int[] dy = { 0, 0, -1, 1 };

	public static void main(String[] args){
		// TODO Auto-generated method stub

		Scanner sc = new Scanner(System.in);
		int T = sc.nextInt();

		for (int tc = 1; tc <= T; tc++) {
			n = sc.nextInt();
			g = sc.nextInt();
			gold = new int[g][2];
			gmap = new int[n][n];
			tmp = new int[g][2];
			for (int i = 0; i < g; i++) {
				gold[i][0] = sc.nextInt() - 1;
				gold[i][1] = sc.nextInt() - 1;
				gmap[gold[i][0]][gold[i][1]] = 1;
			}

			mine = new int[n][n];

			for (int i = 0; i < n; i++) {
				for (int j = 0; j < n; j++) {
					mine[i][j] = sc.nextInt();
				}
			}

			min = 10000;
			count = 0;
			for (int i = 0; i < n; i++) {
				for (int j = 0; j < n; j++) {
					if (mine[i][j] != 0 && gmap[i][j] == 0) {
						cnt = 0;
						dist = new int[n][n];
						bfs(i, j);
					}
				}
			}

			System.out.println("Case #" + tc);
			if (min == 10000) {
				System.out.println(-1);
			} else {
				System.out.println(min - 1);
			}

		}
		sc.close();
	}

	private static void bfs(int x, int y) {
		// TODO Auto-generated method stub
		queue.reset();
		queue.push(x);
		queue.push(y);
		dist[x][y] = 1;
		int r, c, d;
		while (!queue.empty()) {
			r = queue.pop();
			c = queue.pop();
			for (int i = 0; i < 4; i++) {
				int nr = r + dx[i];
				int nc = c + dy[i];

				if (nr >= 0 && nr < n && nc >= 0 && nc < n && dist[nr][nc] == 0
						&& mine[nr][nc] == 1) {
					dist[nr][nc] = dist[r][c] + 1;
					queue.push(nr);
					queue.push(nc);
				}
			}
		}
		int max = -1;
		for (int i = 0; i < g; i++) {
			r = gold[i][0];
			c = gold[i][1];
			d = dist[r][c];
			if (dist[r][c] == 0) {
				return;
			}
			if (d > max) {
				max = dist[r][c];
			}
		}
		if (max != -1 && min > max) {
			min = max;
		}
	}
}

class Queue {
	static int f, r;
	static int[] arr;

	Queue(int c) {
		f = r = 0;
		arr = new int[c];
	}

	boolean empty() {
		return f == r;
	}

	void reset() {
		r = f = 0;
	}

	void push(int data) {
		arr[r] = data;
		r++;
	}

	int pop() {
		f++;
		return arr[f - 1];
	}

}
Leave a Comment