DAY2 

 

T1积木大赛

传送门

题目大意:每次可以选区间[l,r]加1,最少选几次,让每个位置有

它应有的高度。

题解:O(n)扫一遍就好了。后一个比前一个的高度低,那么前一个已经把它覆盖了,

如果高那么就需要+1了。

代码:

#include<iostream>
#include<cstdio>
#define maxn 100009
using namespace std;

int n,x,pre,ans;

void read(int &x){
    char ch=getchar();int f=1;x=0;
    for(;!isdigit(ch);ch=getchar())if(ch=='-')f=-1;
    for(;isdigit(ch);ch=getchar())x=x*10+ch-'0';
    x*=f;
}

int main(){
    freopen("block.in","r",stdin);
    freopen("block.out","w",stdout);
    read(n);
    for(int i=1;i<=n;i++){
        read(x);
        if(x>pre)ans=ans+x-pre;
        pre=x;
    }
    printf("%d\n",ans);
    fclose(stdin);fclose(stdout);
    return 0;
}
AC

相关文章:

  • 2022-12-23
  • 2021-08-01
  • 2021-09-17
  • 2022-12-23
  • 2022-12-23
  • 2021-06-05
  • 2022-12-23
  • 2022-02-22
猜你喜欢
  • 2022-12-23
  • 2022-01-27
  • 2021-10-29
  • 2022-02-23
  • 2021-09-10
  • 2022-12-23
  • 2021-12-10
相关资源
相似解决方案