USACO Bronze 2019 Open - Bucket Brigade
Author: Maggie Liu
Video Solution
By Maggie Liu
Explanation
If there was no rock, then the number of cows needed would just be the horizontal distance between the barn and the lake, plus the vertical distance between the barn and the lake, minus . Adding the rock onto the farm usually doesn't change the answer. The only case where the rock matters is if the rock, barn and lake are on the same line, and the rock is between the barn and the lake. In this case, there will need to be extra cows to go around the rock.
Implementation
C++
#include <cstdio>#include <iostream>using namespace std;int main() {freopen("buckets.in", "r", stdin);freopen("buckets.out", "w", stdout);int barn_i = 0, barn_j = 0, rock_i = 0, rock_j = 0, lake_i = 0, lake_j = 0;for (int i = 0; i < 10; i++) {string row;
Java
import java.io.*;import java.util.*;public class BucketBrigade {public static void main(String[] args) throws IOException {int barnI = 0, barnJ = 0, rockI = 0, rockJ = 0, lakeI = 0, lakeJ = 0;Kattio io = new Kattio("buckets");for (int i = 0; i < 10; i++) {String row = io.next();for (int j = 0; j < 10; j++) {
Python
import syssys.stdin = open("buckets.in", "r")sys.stdout = open("buckets.out", "w")for i in range(10):row = input()for j in range(10):if row[j] == "B":barn_i = i
Join the USACO Forum!
Stuck on a problem, or don't understand a module? Join the USACO Forum and get help from other competitive programmers!