码迷,mamicode.com
首页 > 其他好文 > 详细

PAT 1008

时间:2015-12-09 19:23:11      阅读:141      评论:0      收藏:0      [点我收藏+]

标签:

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

解析:这道题只需要读懂提议即可,一开始我还以为要找到一个最省时间的接人方案,后面发现就是很简单的问题,代码如下。

Code:
/*************************************************************************
    > File Name: 1008.cpp
    > Author: 
    > Mail: 
    > Created Time: 2015年12月09日 星期三 17时02分13秒
 ************************************************************************/

#include<iostream>
using namespace std;

int main(){
    int n;
    cin>>n;
    int m= n;

    int sum = 0;
    int before= 0;
    while(n--){
        int query;
        cin>>query;
        if(query > before){
            sum += (query-before)*6;
        }
        else if(query < before){
            sum += (before-query)*4;
        }

        sum += 5;
        before = query;
    }

    cout<<sum;

    return 0;
}

 

 

PAT 1008

标签:

原文地址:http://www.cnblogs.com/RookieCoder/p/5033557.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!