标签:
简单模拟。
注意a[i]==a[i-1]的情况。
#include<iostream> #include<cstring> #include<cmath> #include<algorithm> #include<cstdio> #include<vector> using namespace std; const int maxn=100+10; int n,a[maxn]; int main() { scanf("%d",&n); for(int i=1;i<=n;i++) scanf("%d",&a[i]); a[0]=0; int ans=0; for(int i=1;i<=n;i++) { if(a[i]>a[i-1]) ans=ans+(a[i]-a[i-1])*6,ans=ans+5; else if(a[i]<a[i-1]) ans=ans+(a[i-1]-a[i])*4,ans=ans+5; else ans=ans+5; } printf("%d\n",ans); return 0; }
PAT (Advanced Level) 1008. Elevator (20)
标签:
原文地址:http://www.cnblogs.com/zufezzt/p/5496070.html