HDOJ_1008_Elevator
AC代码:
#include <iostream> #include <cstdio> #define Max 105 using namespace std; int a[Max]; int main(void) { freopen("in.txt","r",stdin); int n; while(scanf("%d",&n)!=EOF&&n) { int temp=0,i; long long time=0; for(i=1;i<=n;i++) { scanf("%d",&a[i]); if(temp<a[i]) { time+=(a[i]-temp)*6+5; temp=a[i]; } else if(temp>a[i]) { time+=(temp-a[i])*4+5; temp=a[i]; } else { time+=5; } } printf("%lld\n",time); } fclose(stdin); return 0; }