-
Educational Codeforces Round 32 - A. Local Extrema코드포스(CodeForce) 2018. 8. 17. 18:17반응형
1. 문제
2. 알고리즘
키워드 - 구현
* 문제 접근
10분 만에 클리어 허허허허 기적임.
주어진 정수에서 양쪽에 값이 현재 값보다 모두 클때 maxium ++
주어진 정수에서 양쪽에 값이 현재 값보다 모두 작을때 minium ++
3. 코드
12345678910111213141516171819202122232425262728293031323334353637#include <iostream>#include <vector>using namespace std;bool isMaxium(int left, int current, int right){return (current > left) && (current > right);}bool isMinium(int left, int current, int right){return (current < left) && (current < right);}bool isExtremum(int left, int current, int right){return isMaxium(left, current, right) || isMinium(left, current, right);}int main(){int n; cin >> n;vector<int> arr(n);for (int i = 0; i<n; i++)cin >> arr[i];int count = 0;for (int i = 1; i < arr.size() -1; i++) {bool check = isExtremum(arr[i - 1], arr[i], arr[i + 1]);if (check) {count++;}}cout << count << endl;return 0;}cs 반응형'코드포스(CodeForce)' 카테고리의 다른 글
Educational Codeforces Round 34 (Rated for Div. 2) - A.Hungry Student Problem (0) 2018.08.17 Educational Codeforces Round 33 (Rated for Div. 2) - A. Chess For Three (0) 2018.08.17 Educational Codeforces Round 32 - B. Buggy Robot (0) 2018.08.17 Educational Codeforces Round 31 - A. Book Reading (0) 2018.08.17 Educational Codeforces Round 30 - A. Chores (0) 2018.08.17