Elevator
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 26436 Accepted Submission(s): 14247
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.
#include<iostream>
using namespace std;
int main()
{
int n;
int m[100];
while(cin>>n)
{
int a=n,i=0,j,k,sum=0;
if(n==0)
break;
else
{
while(a--)
cin>>m[i++];
sum+=6*m[0];
for(i=0;i<n-1;i++)
{
if(m[i+1]>m[i])
sum+=6*(m[i+1]-m[i]); // 如果i+1层大于i层,就用层数之间的差乘以6
else if(m[i+1]<=m[i])
sum+=4*(m[i]-m[i+1]); // 如果i+1层小于等于i层,就用层数之间的差乘以4
}
sum+=5*n; //每到一层电梯停留,所以每次要乘以5
}
cout<<sum<<endl;
}
return 0;
}