码迷,mamicode.com
首页 > 其他好文 > 详细

noip提高组2013 积木大赛(luogu 1969)

时间:2017-09-19 19:53:44      阅读:199      评论:0      收藏:0      [点我收藏+]

标签:需要   pid   turn   oid   cst   print   return   void   提高   

原题链接:https://www.luogu.org/problem/show?pid=1969

将高度看成一个序列,当出现下降的时候,就将操作次数加上一个记录的层数,然后记录这时的高度,继续向下读入

不过需要注意加上最后的高度。防止最后是一个单调上升。。。
为什么这样是对的呢,因为这样操作是从右向左操作的,左边的高度已知,并且之前的已经处理好

 

#include<cstdio>
int n,h[100015],t,ans;
void read(int &y)
{
    y=0;char x=getchar();
    while(x<0||x>9) x=getchar();
    while(x>=0&&x<=9)
    {
        y=y*10+x-0;
        x=getchar();
    }
}
int main()
{
    read(n);
    for(int i=1;i<=n;i++)
    {
        read(h[i]);
        if(h[i]<h[i-1])
        {
            ans+=h[i-1]-t;
            t=h[i];
        }
    }
    printf("%d",ans+h[n]-t);
    return 0;
}

 

noip提高组2013 积木大赛(luogu 1969)

标签:需要   pid   turn   oid   cst   print   return   void   提高   

原文地址:http://www.cnblogs.com/zeroform/p/7553507.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!