zoukankan      html  css  js  c++  java
  • 【洛谷p1970】花匠

    莫得致敬lz谢谢。lz的题解是优秀的题解谢谢!

    看算法标签

    但是我并不会DP的思路,用一个很神奇的码量超级少的代码(虽然我码了超多),然后其实这个数据可以看做是一个函数嘛对吧:(比如说样例)

    那么要注意题意是偶点只能满足条件A,B中的一个,而不是都可以满足;

    然后这道题的思路就是很简单的:

    寻找共有几段单调区间,然后+1;就是最终答案;

    但是吧,咱不会证明:

    然后代码实现应该也不是太难:

    #include<bits/stdc++.h>
    
    using namespace std;
    
    inline int read() {
        int ans=0;
        char last=' ',ch=getchar();
        while(ch>'9'||ch<'0') last=ch,ch=getchar();
        while(ch>='0'&&ch<='9') ans=(ans<<1)+(ans<<3)+ch-'0',ch=getchar();
        if(last=='-') ans=-ans;
        return ans;
    }
    
    int n,a,m,nxt;
    int sj;//up is 1 and drop is 0 nothing is 2
    
    int main() {
        n=read();nxt=read();
        if(n==1) {
            printf("1");
            return 0;
        }
        a=read();
        if(a>nxt) sj=1;if(a<nxt) sj=0;if(a==nxt) sj=2;
        nxt=a;m=1;
        for(int i=3; i<=n; i++) {
            a=read();
            if(sj==2) {
                if(a>nxt) {sj=1;nxt=a;continue;}
                if(a<nxt) {sj=0;nxt=a;continue;}
                if(a==nxt) {nxt=a;continue;}
            }
            if(sj) {
                if(a>=nxt) {nxt=a;continue;} 
                else {m++;sj=0;nxt=a;}
            } else {
                if(a<=nxt) {nxt=a;continue;} 
                else {m++;sj=1;nxt=a;}
            }
        }
        cout<<m+1<<endl;
        return 0;
    }//lz因为代码太长疯狂压行

    end-

  • 相关阅读:
    阿里云下Linux MySQL的安装
    protocol buffer相关
    Unity NGUI UIPanel下对粒子的剪裁
    NGUI中UILabel用省略号替换超出显示区域的内容
    Go交叉编译
    Unity3d使用未破解的TexturePacker
    编程之美 找出符合条件的整数
    算法导论~
    hadoop资料汇总(网上)
    SOE 中调用第三方dll
  • 原文地址:https://www.cnblogs.com/zhuier-xquan/p/11131507.html
Copyright © 2011-2022 走看看