본문 바로가기

USACO/Bronze

백준 17039 Sleepy Cow Herding (USACO February 2019 Bronze 1번)

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

 

17039번: Sleepy Cow Herding (Bronze)

The minimum number of moves is 1 --- if Farmer John moves the cow in position 4 to position 8, then the cows are at consecutive locations 7, 8, 9. The maximum number of moves is 2. For example, the cow at position 9 could be moved to position 6, then the c

www.acmicpc.net

최소값

1. 세개의 수가  모두 붙어있을때는 0임.

2. 연속된 두수의 차이가 2인  경우가 있을때는 1임.

3. 위의 두상황 모두가 아니면 2임.

최대값

연속된 두수의 차이중에 큰값에서 1을 빼면 됨.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
#include <bits/stdc++.h>
using namespace std;
 
int a[4], mn, mx;
 
int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
 
    for(int i = 0; i < 3; i++cin >> a[i];
    sort(a, a + 3);
 
    if(a[2- a[0!= 2) mn = (a[2- a[1== 2 || a[1- a[0== 2) ? 1 : 2;
    mx = max(a[2- a[1], a[1- a[0]) - 1;
 
    cout << mn << '\n' << mx << '\n';
    return 0;
}
 
http://colorscripter.com/info#e" target="_blank" style="color:#4f4f4ftext-decoration:none">Colored by Color Scripter