Loading

USACO 2019 January Contest, Bronze Problem 2. Sleepy Cow Sorting

Sleepy Cow Sorting

分类讨论

  • 先把答案本就连续的特判丢掉

  • 最大值

最大值就尽量把每个空位都踩一遍,模拟一下会发现,第一跳的空隙一定没办法踩到,因此考虑两边第一跳谁跳的短,就从哪边开始

  • 最小值
  1. 跳一次

如果有两个相邻的,正好中间有个空位,就只用跳一次

  1. 跳两次

两次一定能结束,第一次跳到另一端,并且中间留一个空位,然后就只用跳一次

#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
using namespace std;
typedef long long ll;
#define pii pair<int, int>
const ll maxn = 2e5 + 10;
const ll inf = 1e17 + 10;

int main()
{
    freopen("herding.in", "rb", stdin);
    freopen("herding.out", "wb", stdout);
    vector<int>a(3);
    for(int i=0; i<3; i++) cin >> a[i];
    sort(a.begin(), a.end());
    if(a[0] == a[1] - 1 && a[1] == a[2] - 1) {cout << "0\n0"; return 0;}
    if(a[1] - a[0] == 2 || a[2] - a[1] == 2) cout << 1 << endl;
    else cout << 2 << endl;
    cout << max(a[2] - a[1], a[1] - a[0]) - 1 << endl;
    return 0;
}
posted @ 2022-11-30 00:22  dgsvygd  阅读(121)  评论(0编辑  收藏  举报