题目描述:
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.
1 2 3 2 3 1 0
17 41
大意:上一层楼加六秒,下一层加四秒,需要停的时候一楼层加五秒。。
想法:输入一串数据,后一个楼层数大于前一个,6*差+5。。反之 4*差+5。。
代码:
#include <iostream>
#include <algorithm>
using namespace std;
int main()
{
int m,a=0,sum=0,i,k[101];
while(cin>>m)
{
if(m!=0)
{
for(i=1;i<=m;i++)
{
cin>>k[i];
}
sum=k[1]*6+5;
for(i=2;i<=m;i++)
{
if(k[i]>k[i-1])
sum=sum+5+6*(k[i]-k[i-1]);
else sum=sum+5+4*(k[i-1]-k[i]);
}
cout<<sum<<endl;
}
}
}
感想:挺简单的,没怎么花时间。。