Elevator
来源:互联网 发布:mac上能玩的网游 编辑:程序博客网 时间:2024/06/05 23:39
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.
10
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.
#include <iostream>using namespace std;void sort (int *p);int i;int main (){ int table[110]={0}; int count = 0, second; i = 0; do { cin >> table[i]; i++; }while(table[i-1]!=0); sort(table); for(int j = 0; j < i-1; j++) { if(table[j]!=table[j+1]) count++; } second = 6*table[i-2] + 4*(table[i-2]-table[0]) + 5*(count); cout << second << endl; return 0;}void sort (int *p){ int temp; for(int j = 0; j < i-1; j++) { for(int k = 0; k < i-j-2; k++) { if(*(p+k) > *(p+k+1)) { temp = *(p+k); *(p+k) = *(p+k+1); *(p+k+1) = temp; } } }}
- Elevator
- Elevator
- Elevator
- elevator
- Elevator
- Elevator
- Elevator
- Elevator
- Elevator
- elevator
- Elevator
- Elevator
- Elevator
- Elevator
- Elevator
- Elevator
- Elevator
- Elevator
- jarsperreports生成PDF中文不显示问题
- 在GridView在添加最后一行的总计一列,怎么把6个零变成3个零,在后台处理
- Java 的深拷贝和浅拷贝
- JMS-ActiveMQ
- Android总结之style(样式)和Theme(主题)
- Elevator
- 关于Android 5.0以上截屏API MediaProjection的使用方式总结
- 我的感受
- linux iptables实现单机多ip出口ip负载均衡(宽带叠加)
- CSS选择器
- Android7.0 PowerManagerService(4) Power按键流程
- java.lang.AssertionError: UNIMPLEMENTED
- source insight 怎么查看当前文件所在路径
- Superset 通过 Presto 连接 HDFS