문제 링크: https://www.acmicpc.net/problem/17028
17028번: Sleepy Cow Sorting
Farmer John is attempting to sort his $N$ cows ($1 \leq N \leq 100$), conveniently numbered $1 \dots N$, before they head out to the pastures for breakfast. Currently, the cows are standing in a line in the order $p_1, p_2, p_3, \dots, p_N$, and Farmer Joh
www.acmicpc.net
뒤에서부터 제대로 정렬이 된 갯수를 전체 갯수에서 빼면 됨.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
|
#include <bits/stdc++.h>
using namespace std;
int n, a[101];
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cin >> n;
for(int i = 0; i < n; i++) cin >> a[i];
int cnt = 1;
for(int i = n - 1; i >= 1; i--) {
if(a[i - 1] < a[i]) cnt++;
else break;
}
cout << n - cnt << '\n';
return 0;
}
http://colorscripter.com/info#e" target="_blank" style="color:#4f4f4ftext-decoration:none">Colored by Color Scripter
|
'USACO > Bronze' 카테고리의 다른 글
백준 17039 Sleepy Cow Herding (USACO February 2019 Bronze 1번) (0) | 2020.03.14 |
---|---|
백준 17029 Guess the Animal (USACO January 2019 Bronze 3번) (0) | 2020.03.14 |
백준 17027 Shell Game (USACO January 2019 Bronze 1번) (0) | 2020.03.13 |
백준 16770 The Bucket List (USACO December 2018 Bronze 2번) (0) | 2020.03.13 |
백준 16769 Mixing Milk (USACO December 2018 Bronze 1번) (0) | 2020.03.13 |