记录编号 99100 评测结果 AAAAAAAAAA
题目名称 [NOIP 2013]花匠 最终得分 100
用户昵称 GravatarAsm.Def 是否通过 通过
代码语言 C++ 运行时间 0.024 s
提交时间 2014-04-25 20:05:28 内存使用 11.73 MiB
显示代码纯文本
//<NOIP2013> 花匠
#include <cstdio>
#include <cmath>
using namespace std;

int maxm(int a, int b)
{
	if(a >= b )return a ;
        else return b;
}

const int maxn = 1000005;
int h[maxn] = {0};  //
int n;
int S1[maxn], S2[maxn] ;
//(1尾部为升序,2尾部为降序)

int main(void)
{
	FILE *in = fopen ("FlowerNOIP2013.in","r");
	FILE *out = fopen ("FlowerNOIP2013.out" ,"w");
	fscanf(in, "%d", &n);
	int i;
	for(i = 1; i <= n; i++)
		fscanf(in, "%d", &h[i]);
	S1[1] = S2[1] = 1;   //初始状态
	
	for(int i = 2;i <= n; i++)
	{
		if(h[i] > h[i-1]) // case1
		{
			S1[i] = maxm(S1[i-1], S2[i-1]+1 );
			S2[i] = S2[i-1];
		}
		else if (h[i] == h[i-1])// case2
		{
			S1[i] = S1[i-1];
			S2[i] = S2[i-1];
		}
		else	//case 3
		{
			S1[i] = S1[i-1];
			S2[i] = maxm(S1[i-1]+1, S2[i-1] );
		}
	}
    
	fprintf(out, "%d", maxm(S1[n], S2[n]) );
	return 0;
}