PAT 1008
来源:互联网 发布:汽车仪表单片机 编辑:程序博客网 时间:2024/05/17 13:42
1008. Elevator (20)
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 Specification:
Each input file contains one test case. Each case contains a positive integer N, followed by N positive numbers. All the numbers in the input are less than 100.
Output Specification:
For each test case, print the total time on a single line.
Sample Input:3 2 3 1Sample Output:
41
直接上代码
2
3 int main()
4 {
5 int N;
6 int sum;
7 int i;
8 int start_pos,end_pos;
9 while(scanf("%d",&N) != EOF){
10 sum = 0;
11 start_pos = 0;
12 for(i=0;i<N;++i){
13 scanf("%d",&end_pos);
14 if(start_pos < end_pos){
15 sum = sum + 6 * (end_pos - start_pos);
16 }
17 else{
18 sum = sum + 4 * (start_pos - end_pos);
19 }
20 start_pos = end_pos;
21 }
22 sum = sum + 5 * N;
23 printf("%d\n",sum);
24 }
25 return 0;
26 }
- PAT 1008
- PAT 1008
- pat 1008
- PAT 1008
- PAT 1008
- PAT 1008
- PAT 1008
- pat 1008
- PAT 1008
- PAT 1008
- PAT 1008
- PAT 1008
- PAT 1008
- PAT 1008
- PAT Basic 1008
- PAT BASIC 1008
- PAT(A) 1008
- PAT Basic 1008
- PAT 1005
- ASP.NET的Cookie
- PAT 1006
- PAT 1007
- Jordan Lecture Note-2: Maximal Margin Classifier
- PAT 1008
- PAT 1009
- Jordan Lecture Note-3: 梯度投影法
- PAT 1010
- PAT 1011
- PAT 1012
- Jordan Lecture Note-4: Linear & Ridge Regression
- Jordan Lecture Note-5: Kernels
- PAT 1013