zoukankan      html  css  js  c++  java
  • 1008. Elevator (20)

     

    时间限制
    400 ms
    内存限制
    65536 kB
    代码长度限制
    16000 B
    判题程序
    Standard
    作者
    CHEN, Yue

    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<stdio.h>
     4 
     5 int main()
     6 {
     7     
     8     int n,i,tem;
     9     while(scanf("%d",&n)!=EOF)
    10     {
    11         int index= 0;
    12         int sum = 0;
    13         for(i= 0;i<n;i++)
    14         {
    15             scanf("%d",&tem);
    16             int dis = tem - index;
    17             if(dis > 0)
    18             {
    19                 sum += dis * 6;
    20             }
    21             else
    22             {
    23                 sum -= dis * 4;
    24             }
    25 
    26             sum += 5;
    27             index = tem ;
    28         }
    29 
    30         printf("%d
    ",sum);
    31     }
    32     return 0;
    33 }
  • 相关阅读:
    班别:批量添加导师
    批量删除注入字段,触发器防止注入。
    c#生成不重复随机数
    网络蜘蛛爬虫程序
    session丢失问题整理
    asp.net 自动生成控件
    C#实现所有经典排序算法 收藏
    泛型学习
    Android 判断网络并打开设置界面
    Android 获取Android手机中SD卡存储信息 获取剩余空间
  • 原文地址:https://www.cnblogs.com/xiaoyesoso/p/4277110.html
Copyright © 2011-2022 走看看