Skip to content

USACO 2019 February Contest Bronze Division - Sleepy Cow Herding#

Problem link: here

Solution Author: Stefan Dascalescu

Problem Solution#

We will have some casework based on the distances between the three points.

Source codes#

The source codes in C++ and Python can be seen below.

#include <bits/stdc++.h>
using namespace std;


int main()
{
    ifstream cin("herding.in");
    ofstream cout("herding.out");

    int a, b, c;
    cin >> a >> b >> c;

    vector<int> v = {a, b, c};
    sort(v.begin(), v.end());

    if(v[2] - v[0] == 2)
        cout << 0 << '\n';
    else
        if(v[1] - v[0] == 2 || v[2] - v[1] == 2)
            cout << 1 << '\n';
        else
            cout << 2 << '\n';
    cout << max(v[1] - v[0], v[2] - v[1]) - 1 << '\n';
    return 0;

}
with open("herding.in", "r") as fin:
    a, b, c = map(int, fin.readline().split())
v = sorted([a, b, c])
if v[2] - v[0] == 2:
    first = 0
elif v[1] - v[0] == 2 or v[2] - v[1] == 2:
    first = 1
else:
    first = 2
second = max(v[1] - v[0], v[2] - v[1]) - 1
with open("herding.out", "w") as fout:
    fout.write(str(first) + "\n" + str(second) + "\n")