zoukankan      html  css  js  c++  java
  • 花匠sol

    花匠
    只要记录有几个峰几个谷就行了

    #include<bits/stdc++.h>
    #define fi first
    #define se second
    #define pb push_back
    #define mp make_pair
    #define SZ(x) ((int)x.size())
    #define ALL(x) x.begin(),x.end()
    #define U(i,u) for(register int i=head[u];i;i=nxt[i])
    #define rep(i,a,b) for(register int i=(a);i<=(b);++i)
    #define per(i,a,b) for(register int i=(a);i>=(b);--i)
    using namespace std;
    typedef long double ld;
    typedef long long ll;
    typedef unsigned int ui;
    typedef pair<int,int> PII;
    typedef vector<int> VI;
    template<class T> inline void read(T &x){
    	x=0;char c=getchar();int f=1;
    	while(!isdigit(c)){if(c=='-')f=-1;c=getchar();}
    	while(isdigit(c)){x=x*10+c-'0';c=getchar();}x*=f;
    }
    template<class T> inline void cmin(T &x, T y){x=x<y?x:y;}
    template<class T> inline void cmax(T &x, T y){x=x>y?x:y;}
    const int N=100001;
    int n,a[N],ans=0,tmp;
    int main(){
    	read(n);rep(i,1,n)read(a[i]);
    	ans=2;tmp=a[2]>=a[1];rep(i,2,n-1){
    		if(tmp==1&&a[i+1]<a[i])++ans,tmp=0;
    		else if(tmp==0&&a[i+1]>a[i])++ans,tmp=1;
    	}
    	printf("%d",ans);
    	return 0;
    }
    
  • 相关阅读:
    Ubuntu16.04更新记
    「BZOJ2153」设计铁路
    [UVA-11995]I Can Guess the Data Structure!
    [UVA-11100] The Trip
    [UVA-11039]Children's Game
    [BZOJ1008][HNOI2008]越狱
    NOIP2018退役祭
    修马路
    [NOIP2005]过河
    [POJ1958][Strange Tower of Hanoi]
  • 原文地址:https://www.cnblogs.com/hangzz/p/13381832.html
Copyright © 2011-2022 走看看