題目連結: https://codeforces.com/problemset/problem/1380/A

# 內容

給你一串數列pp,尋找符合條件的i,j,ki,j,k:

  • 1i<j<kn;1≤i<j<k≤n;
  • pi<pjandpj>pkpi<pj and pj>pk
    或說 沒有找到

# 思路

如果有解答案必不為遞增或遞減數列,因此一定會存在相鄰的元素滿足pi<pjandpj>pkpi<pj and pj>pk

# 程式碼

#include <bits/stdc++.h>
using namespace std;
const int N = 1000;
 
int n;
int a[N];
 
void solve() {
	cin >> n;
	for (int i = 0; i < n; ++i)
		cin >> a[i];
	for (int i = 1; i < n - 1; ++i) {
		if (a[i] > a[i - 1] && a[i] > a[i + 1]) {
			cout << "YES" << endl;
			cout << i << ' ' << i + 1 << ' ' << i + 2 << endl;
			return;
		}
	}
	cout << "NO" << endl;
}
 
int main() {
	int T;
	cin >> T;
	while (T--)
		
}
更新於 閱讀次數

用實際行動犒賞爆肝的我😀

Zrn Ye LinePay

LinePay