#include<stdio.h>
#include<string.h>
int main()
{
    int a,i,n,m,k,t=0,b=0;
    scanf("%d",&n);
    for(i=1;i<=n;i++)
    {
        scanf("%d",&a);
        if(i==1)t=a;
        else 
        {    if(a>=b)t+=a-b+1;
            else t+=b-a+1;
        }
        b=a;
    }
            printf("%d",t+n);
            return 0;
}
#include<stdio.h>
#include<string.h>
int main()
{
    int a,i,n,m,k,t=0,b=0;
    scanf("%d",&n);
    for(i=1;i<=n;i++)
    {
        scanf("%d",&a);
        if(i==1)t=a;
        else 
        {    if(a>=b)t+=a-b+1;
            else t+=b-a+1;
        }
        b=a;
    }
            printf("%d",t+n);
            return 0;
}

http://codeforces.com/contest/265/problem/B

posted on 2013-01-21 00:24  海暗  阅读(134)  评论(0编辑  收藏  举报