> For the complete documentation index, see [llms.txt](https://tobigs.gitbook.io/usaco-week2/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://tobigs.gitbook.io/usaco-week2/j.-bucket-brigade.md).

# J. Bucket Brigade

### 문제 설명&#x20;

B에서 L로 도달하는데 R만 피하면 됩니다.

여기서 R이나 L이 여러개면 BFS로 최단경로 탐색을 해야하지만

(문제 설명에 조건이 누락되어 있는데) B, L, R은 단 한개씩입니다.

그래서 B - R - L(또는 L - R - B)이 일직선으로 있는 경우만 예외처리해서 단순하게 구현하면 됩니다.

### 소스 코드 (C++)

```cpp
#include <iostream>
using namespace std;

int Bx, By, Rx, Ry, Lx, Ly, ans;

int main() {
	for (int i = 0; i < 10; i++) for (int j = 0; j < 10; j++) {
		char t;
		cin >> t;
		if (t == 'B') { Bx = i; By = j; }
		if (t == 'R') { Rx = i; Ry = j; }
		if (t == 'L') { Lx = i; Ly = j; }
	}

	ans = abs(Bx - Lx) + abs(By - Ly) - 1;

	if (Bx == Rx && Rx == Lx) {
		if (By < Ry && Ry < Ly)
			ans = 1 + abs(By - Ly);
		else if (Ry < By && Ly < Ry)
			ans = 1 + abs(By - Ly);
	}
		
	else if (By == Ry && Ry == Ly) {
		if (Bx < Rx && Rx < Lx)
			ans = 1 + abs(Bx - Lx);
		else if (Lx < Rx && Rx < Bx)
			ans = 1 + abs(Bx - Lx);
	}

	cout << ans << endl;
}
```


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://tobigs.gitbook.io/usaco-week2/j.-bucket-brigade.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
