标签:
题意:给定 n 个数,问你连续的最长的序列是几个。
析:从头扫一遍即可。
代码如下:
#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 = 0x3f3f3f3f; const double inf = 0x3f3f3f3f3f3f3f; const double eps = 1e-8; const int maxn = 1e5 + 5; const int dr[] = {0, 0, -1, 1}; const 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 (贪心,高效算法)
标签:
原文地址:http://www.cnblogs.com/dwtfukgv/p/5720315.html