Test instructions: Given n number, ask you the longest sequence of consecutive is several.
Analysis: From the beginning to sweep again.
The code is as follows:
#include <cstdio> #include <string> #include <cstdlib> #include <cmath> #include <iostream > #include <cstring> #include <set> #include <queue> #include <algorithm> #include <vector > #include <map>using namespace std; typedef long Long Ll;typedef pair<int, int> p;const int INF = 0x3f3f3f3 F;const Double inf = 0x3f3f3f3f3f3f3f;const double EPS = 1e-8;const int maxn = 1e5 + 5;const int dr[] = {0, 0,-1, 1};cons t int dc[] = {-1, 1, 0, 0};int N, m;inline bool is_in (int r, int c) {return R >= 0 && r < n && C >= 0 && C < m;} int A[maxn];int Main () {CIN >> n; for (int i = 1; I <= n; ++i) scanf ("%d", &a[i]); int ans = 1; int s = 0, E = 2; int cnt = 0; A[0] = 0; while (e <= n) {cnt = 1; while (e <= n && a[e] > a[e-1]) {++cnt; ++e; } ans = max (ans, CNT); ++e; } cout << ans << endl; return 0;}
Codeforces 702 A Maximum Increase (greedy, efficient algorithm)