【HDOJ】1008 Elevator

【题目】 http://acm.hdu.edu.cn/showproblem.php?pid=1008

【报告】

    这是我在HDOJ里看到的最水的题目,至少目前为止。

    题目里已经讲得很清楚了,模拟就能过的,不过还得考虑读入输出超时以及ANS超范围,于是,轻松解决……

【程序】

// TASK: 1008 Elevator
#include <cstdlib>
#include <iostream>
#include <algorithm>
#include <cstdio>
using namespace std;
long n,m;
long long ans;
int main(int argc, char *argv[])
{
    while (scanf("%d",&n))
    {
          if (n<=0) break;
          ans=0;
          m=0;
          for (long i=1,q;i<=n;i++)
          {
              scanf("%d",&q);
              if (q>m)
                 ans+=6*(q-m);
              else ans+=4*(m-q);
              m=q;
              ans+=5;
          }
          printf("%d\n",ans);
    }
 //   system("PAUSE");
    return EXIT_SUCCESS;
}

 

posted @ 2012-08-28 10:37  为美好世界献上珂学  阅读(78)  评论(0)    收藏  举报