【洛谷】积木大赛

(原题传送门)

思路

(有待更新)

90分Code

#include<cstdio>

using namespace std;

int main()
{
    freopen("in.txt","r",stdin);
    //读入
    int ans=0,n;
    int h[100001];
    scanf("%d",&n);
    for(int i=1;i<=n;i++)scanf("%d",&h[i]); 
    
    //装叉走起
    for(int i=1;i<=n;i++)
    {
        while(h[i]!=0)
        {
            for(int j=i;j<=n;j++)
            if(h[j]==0)break;
            else h[j]--;
            ans++;
        }
    }
    
    //输出
    printf("%d",ans);
    return 0;
}

AC-Code

#include<cstdio>
using namespace std;
int s,n,ans,now;
int main()
{
    int i;
    scanf("%d",&n);
    scanf("%d",&ans);
    now=ans;//记录当前目标积木高度
    for(i=1;i<n;i++)
    {
        scanf("%d",&s);
        if(s>now) ans+=(s-now);
        now=s;//更新现在目标的值
    }
    printf("%d",ans);
    return 0; 
}

猜你喜欢

转载自www.cnblogs.com/gongdakai/p/10959266.html