본문 바로가기

USACO/Bronze

백준 17198 Bucket Brigade (USACO US Open 2019 Bronze 1번)

문제 링크: https://www.acmicpc.net/problem/17198

 

17198번: Bucket Brigade

The input file contains 10 rows each with 10 characters, describing the layout of the farm. There are exactly one barn, one lake, and one rock.

www.acmicpc.net

 

불과 연못이 일직선상에 있으면서 그 사이에 바위가 있는 경우에 살짝 돌아가야 하는 부분만 처리해주면 됨.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
#include <bits/stdc++.h>
using namespace std;
 
int bx, by, rx, ry, lx, ly, ans;
char farm[11][11];
 
int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
 
    for(int i = 0; i < 10; i++for(int j = 0; j < 10; j++) {
        cin >> farm[i][j];
        if(farm[i][j] == 'B') by = i, bx = j;
        if(farm[i][j] == 'R') ry = i, rx = j;
        if(farm[i][j] == 'L') ly = i, lx = j;
    }
 
    ans = abs(bx - lx) + abs(by - ly) - 1;
    if(by == ry && ry == ly) {
        if(bx < rx && rx < lx || bx > rx && rx > lx)
            ans = abs(bx - lx) + 1;
    }
    if(bx == rx && rx == lx) {
        if(by < ry && ry < ly || by > ry && ry > ly)
            ans = abs(by - ly) + 1;
    }
 
    cout << ans << '\n';
    return 0;
}
 
http://colorscripter.com/info#e" target="_blank" style="color:#4f4f4ftext-decoration:none">Colored by Color Scripter