本文共 1430 字,大约阅读时间需要 4 分钟。
1、题目描述:
Description
The highest building in our city has only one elevator. A request list is made up with N positive numbers. The numbers denote at which floors the elevator will stop, in specified order. It costs 6 seconds to move the elevator up one floor, and 4 seconds to move down one floor. The elevator will stay for 5 seconds at each stop.
For a given request list, you are to compute the total time spent to fulfill the requests on the list. The elevator is on the 0th floor at the beginning and does not have to return to the ground floor when the requests are fulfilled.Input
Output
Sample Input
Sample Output
2、代码:
#includeint a[105];int main(){ int n; while(scanf("%d",&n)!=EOF) { if(n==0) break; int sum=0; for(int i=1;i<=n;i++) scanf("%d",&a[i]); for(int i=1;i<=n;i++) { if(a[i]-a[i-1]>0) sum+=(a[i]-a[i-1])*6; else sum+=(a[i-1]-a[i])*4; } sum+=5*n; printf("%d\n",sum); } return 0;}
转载地址:http://phddi.baihongyu.com/