[Codeforces Round #162 (Div. 2)]B. Roadside Trees (Simplified Edition)

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

爬树吃坚果,很明显树顶走是最短路

 1 #include<stdio.h>
 2 
 3 int n,h[2];
 4 
 5 int main()
 6 {
 7     int i,ans=0;
 8     scanf("%d",&n);
 9     for(i=0;i<n;i++)
10     {
11         scanf("%d",&h[1]);
12         if(0==i)
13         {
14             ans=h[1]+1;
15             h[0]=h[1];
16         }
17         else
18         {
19             if(h[1]>=h[0]) ans=ans+h[1]-h[0]+2;
20             else ans=ans+h[0]-h[1]+2;
21             h[0]=h[1];
22         }
23     }
24     printf("%d\n",ans);
25     return 0;
26 }

 

posted @ 2013-01-21 23:33  tjsuhst  阅读(307)  评论(0)    收藏  举报