枚举断点
牛牛的数列
https://ac.nowcoder.com/acm/problem/13142
lf[i]代表从i往左递增序列的最大长度
rg[i]代表从i往右递增序列的最大长度
然后枚举每一个断点
#include <iostream> #include <vector> #include <map> #include <unordered_map> #include <algorithm> #include <set> #include <string> #include <sstream> #include <stack> #include <algorithm> #include <queue> #include <numeric> using namespace std; int main() { int n; cin >> n; vector<int> vec; int lf[100005]{ 0 }; int rg[100005]{ 0 }; for (int i = 0; i < n; i++) { int tmp; cin >> tmp; vec.push_back(tmp); rg[i]=lf[i] = 1; } for (int i = 1; i < n; i++) { if (vec[i] > vec[i - 1]) { lf[i] = lf[i-1] + 1; } } for (int i = n - 2; i >= 0; i--) { if (vec[i] < vec[i + 1]) { rg[i] = rg[i+1] + 1; } } int ans=1; for (int i = 0; i < n; i++) { int k = 0; if (i == 0) { k = rg[i]; } else if (i == n - 1) { k = lf[i]; } else { if ( vec[i+1] - vec[i-1]>=2 ) { k = lf[i - 1] + rg[i+1]+1; } } ans = max(ans, k); } cout<<ans; return 0; }