PAT1008. Elevator

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 1

Sample Output:

41思路:进行简单模拟即可

 1 #include <iostream>
 2 #include <cstdio>
 3 using namespace std;
 4 #define MAX  200
 5 int data[MAX];
 6
 7
 8 int main(int argc, char *argv[])
 9 {
10     int N;
11     scanf("%d",&N);
12     for(int i=0;i<N;i++)
13     {
14         scanf("%d",&data[i]);
15     }
16     int cost=0; //6 4 5
17     int now=0; //目前在第几层
18     int i=0;
19     while(i<N)
20     {
21         int des=data[i];
22         if(des>now)
23         {
24             while(now<des)
25             {
26               cost+=6;
27               now++;
28             }
29         }
30         else
31         {
32             while(now>des)
33             {
34                 cost+=4;
35                 now--;
36             }
37         }
38         cost+=5;
39         i++;
40     }
41     printf("%d\n",cost);
42     return 0;
43 }

时间: 2025-01-31 06:19:48

PAT1008. Elevator的相关文章

Elevator

Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u 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 s

hdu 1008 elevator

#include<iostream> #include<stdio.h> #include<math.h> #include<algorithm> using namespace std; int main() { int n; while(~scanf("%d",&n)&&n!=0) { int a,b; a=0; int ans=0; for(int i=0;i<n;i++) { scanf("

poj 2392 Space Elevator (多重背包)

Space Elevator Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 8110   Accepted: 3843 题目大意  :一群牛要上天  用一些石块堆塔  给出石块的种类  及其每个种类的数量 和该种石块能出现的最高高度  和每种石块的数量 求怎么摆放才能堆得最高 多重背包模板题.... 将所有石块排序  把高度低的放下面 #include<iostream> #include<cstdio>

POJ2392Space Elevator(贪心+背包)

Space Elevator Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 9970   Accepted: 4738 Description The cows are going to space! They plan to achieve orbit by building a sort of space elevator: a giant tower of blocks. They have K (1 <= K <

poj 2392 Space Elevator(多重背包+先排序)

Description The cows are going to space! They plan to achieve orbit by building a sort of space elevator: a giant tower of blocks. They have K (1 <= K <= 400) different types of blocks with which to build the tower. Each block of type i has height h

XTUOJ 1206 Dormitory&#39;s Elevator

Dormitory's Elevator Time Limit : 1000 MS   Memory Limit : 65536 KB Problem Description The new dormitory has N(1≤N≤100000) floors and M(1≤M≤100000)students. In the new dormitory, in order to save student's time as well as encourage student exercise,

1008. Elevator

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 seco

POJ2392Space Elevator(多重背包)

Space Elevator Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 8701   Accepted: 4135 Description The cows are going to space! They plan to achieve orbit by building a sort of space elevator: a giant tower of blocks. They have K (1 <= K <

Elevator poj3539

Elevator Time Limit: 4000MS   Memory Limit: 65536K Total Submissions: 1072   Accepted: 287 Case Time Limit: 2000MS Description Edward works as an engineer for Non-trivial Elevators: Engineering, Research and Construction (NEERC). His new task is to d