CCF-折点计数
作者:互联网
#include<iostream>
#include<cmath>
#include<algorithm>
#include<string>
#include<vector>
#include<cstdio>
#include<cstring>
#include<queue>
using namespace std;
int main()
{
int n;
cin>>n;
int *a=new int [n];
int ans=0;
for(int i=0;i<n;i++)
{
cin>>a[i];
}
if(n==1)
{
cout<<0<<endl;
return 0;
}
int *b=new int [n-1];
for(int i=0;i<n-1;i++)
{
b[i]=a[i+1]-a[i];
}
bool flag=true;
int i=0;
while(i<n-1)
{
if(b[i]>0)
{
//flag=true;
//i++;
while(b[i]>0)
{
i++;
if(i==n-1)
{
break;
}
}
ans++;
}
else if(b[i]<0)
{
//flag=false;
//i++;
while(b[i]<0)
{
i++;
if (i==n-1)
{
break;
}
}
ans++;
}
}
ans--;
cout<<ans<<endl;
return 0;
}
标签:std,main,include,int,++,计数,折点,ans,CCF 来源: https://blog.csdn.net/IT_flying625/article/details/97486728