USACO/Bronze
백준 17028 Sleepy Cow Sorting (USACO January 2019 Bronze 2번)
ssam..
2020. 3. 13. 22:19
문제 링크: 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
|