1346. Intervals of Monotonicity

http://acm.timus.ru/problem.aspx?space=1&num=1346

题目超级水

代码:

#include<iostream>

#include<cstdio>

#include<cstring>

#include<algorithm>

#include<string>

#include<vector>

#include<set>

#include<queue>

#include<stack>

#include<cmath>

#define LL long long



using namespace std;

const int N=100005;

int a[N];

int main()

{

    //freopen("data","r",stdin);

    int s,n;

    while(scanf("%d %d",&s,&n)!=EOF)

    {

        for(int i=s;i<=n;++i)

        {

            cin>>a[i];

        }

        int k=0;

        int ans=1;

        for(int i=s+1;i<=n;++i)

        {

            if(a[i]==a[i-1])

            {continue;}

            if(a[i]>a[i-1])

            {

                if(k==-1)

                {++ans;k=0;}

                else

                k=1;

            }else

            {

                if(k==1)

                {++ans;k=0;}

                else

                k=-1;

            }

        }

        cout<<ans<<endl;

    }

    return 0;

}

  

你可能感兴趣的:(int)