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;
    }
  • 相关阅读:
    mongodb 简单的更新语句
    centos 安装ffmpeg 及h264编码打包
    mongodb $where查询
    javascript 上传进度条
    javascript 仿豆瓣读书笔记
    js监听浏览器剪贴板
    ffmpeg相关操作
    ffmpeg未整理好,有时间整理下
    fffmpeg 提取pcm
    ffmpeg转MP4 moov头在前命令
  • 原文地址:https://www.cnblogs.com/dreamzj/p/14905088.html
Copyright © 2011-2022 走看看