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;
    }
  • 相关阅读:
    《Thinking In C#》
    在图片上写字
    在设计期跟踪代码
    VS2003下的重构工具ReSharp
    监视剪贴板的变化
    一次重构导向设计模式的实践
    JENA学习的零散笔记
    jena处理Owl
    Maven库中.lastUpdated文件自动清除工具
    WEB数据挖掘(六)——Aperture数据抽取(2)
  • 原文地址:https://www.cnblogs.com/dreamzj/p/14905088.html
Copyright © 2011-2022 走看看