首页 > 代码库 > PAT 1085. Perfect Sequence
PAT 1085. Perfect Sequence
还好只是要求长度,如果是完整序列的话估计得跪
#include <cstdio>#include <climits>#include <cstdlib>#include <algorithm>using namespace std;int main() { int N,p; scanf("%d%d", &N, &p); if (N < 1) { printf("%d\n", 0); return 0; } vector<int> seq(N); for (int i=0; i<N; i++) { scanf("%d", &seq[i]); } if (N < 2) { printf("%d\n", 1); return 0; } sort(seq.begin(), seq.end()); long long m = seq[0]; long long M = seq[0]; int i = 0, j = 1; int max_len = 1; int cur_len = 1; while (i < j && j < N) { m = seq[i]; M = seq[j]; if (M <= m * p) { cur_len = j - i + 1; j++; } else { while (M > m * p) { m = seq[++i]; } } if (cur_len > max_len) { max_len = cur_len; } } printf("%d\n", max_len); return 0;}
PAT 1085. Perfect Sequence
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。