蒟蒻の问题
  • 板块P6510 奶牛排队
  • 楼主imfkwk
  • 当前回复2
  • 已保存回复2
  • 发布时间2021/1/14 23:03
  • 上次更新2023/11/5 04:49:42
查看原帖
蒟蒻の问题
389540
imfkwk楼主2021/1/14 23:03

这题不就是要求一个区间使得 i<j 且a[i]<a[j] 然后求所有满足条件的区间的长度的最大值吗?觉得这个思路没有问题,但是码不能过。那么这个思路哪里错了呢?求大佬举出反例。


代码如下

#include <bits/stdc++.h>
using namespace std;

int n;
int h=1, t=1;
int a[100001];
int ans;

int main() {
	scanf("%d", &n);
	
	for (int i=1; i<=n; i++) {
		scanf("%d", &a[i]);
	}
	
	while (t <= n) {
		while ( (a[t+1]>a[t]) && (t<n) ) {
			t = t + 1;
		}
		ans  = max(ans, t-h+1);
		t = t + 1;
		h = t;
	}
	
	if (ans == 1) ans = 0;
	
	printf("%d", ans);
	
	return 0;
}
2021/1/14 23:03
加载中...