G
来源:互联网 发布:php设置跨域请求的头 编辑:程序博客网 时间:2024/04/29 10:24
Problem 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.
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
There are multiple test cases. Each case contains a positive integer N, followed by N positive numbers. All the numbers in the input are less than 100. A test case with N = 0 denotes the end of input. This test case is not to be processed.
Output
Print the total time on a single line for each test case.
Sample Input
1 23 2 3 10
Sample Output
1741
电梯上一层6s下一层4s停5s,单纯的循环求解
代码
#include<iostream>
#include<vector>
using namespace std;
int main()
{
int n;
#include<vector>
using namespace std;
int main()
{
int n;
while(cin>>n&&n!=0)
{ vector<int >v;
v.push_back(0);
int result=0;
int temp;
for(int i=0;i<n;i++)
{
cin>>temp;
v.push_back(temp);
}
for(int i=1;i<n+1;i++ )
{
if(v[i]>v[i-1])
{
result=result+(v[i]-v[i-1])*6;
}
else if(v[i]<v[i-1])
{
result=result+(v[i-1]-v[i])*4;
else if(v[i]<v[i-1])
{
result=result+(v[i-1]-v[i])*4;
}
}
result= result+n*5;
cout<< result<<endl;
result= result+n*5;
cout<< result<<endl;
}
return 0;
}
}
0 0
- G#
- g
- G++
- g
- g
- g
- g
- G
- g++
- g
- G
- g++
- G
- G - 。。。。。。。
- g
- G
- G
- G
- 教务管理系统-数据库2
- 基于自主开发Web服务器的校内成绩查询系统
- Windows版本编译运行React Native官方实例UIExplorer项目
- vmware不能上网?
- Memcache,Redis,MongoDB(数据缓存系统)方案对比与分析
- G
- javascript数值介绍
- ECMAScript6中的一些小知识 json中的键和值一样,可以只写一个
- C++一些数字的求法
- Oracle中关于(汉字)字符问题
- maximum-depth-of-binary-tree
- CATransform3D
- Android 中调用线程thread.stop 方法后报错,Deprecated Thread methods are not supported.
- 建立Models