zoukankan      html  css  js  c++  java
  • 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 1
     

    Sample Output:

    41

    思路:讲每个楼层存进数组中,每一层与前一个元素比较大小,用差值乘以时间,再加上停留时间即可

    #include<bits/stdc++.h>
    using namespace std;
    const int maxn=10010;
    
    int main(){
        int nums[maxn];
        int n;
        scanf("%d",&n);
        nums[0]=0;
        for(int i=1;i<=n;i++){
            scanf("%d",&nums[i]);
        }
        int sum=0;
        for(int i=1;i<=n;i++){
            if(nums[i]>nums[i-1]){
                sum=sum+(nums[i]-nums[i-1])*6+5;
            }
            else{
                sum=sum+(nums[i-1]-nums[i])*4+5;
            }
        }
        printf("%d
    ",sum);
        return 0;
    }
  • 相关阅读:
    各种alloc傻傻分不清楚
    嵌入式开发一般流程
    谈谈看门狗在嵌入式中的用法
    基于开发板的二次嵌入式开发
    谈一谈接口电路
    学习ucos和ARM体系结构的路线图
    寻找链表的中位节点(利用快慢指针)
    水箱容积问题
    盛水最多的容器
    数据结构与算法分析C语言描述第二版第79页
  • 原文地址:https://www.cnblogs.com/dreamzj/p/14905088.html
Copyright © 2011-2022 走看看