# USACO 2019 January Contest, Bronze Problem 2. Sleepy Cow Sorting()-其他

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

Sleepy Cow Sorting

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

• 最小值
• 跳一次

• 跳两次

``````#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;
}
``````
————————

Sleepy Cow Sorting

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

• 最小值
• 跳一次

• 跳两次

``````#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;
}
``````