HDU1008 Elevator

问题链接:HDU1008 Elevator。基础训练题,用C语言编写程序。

每行的数据有n+1个数据,第一个数据是n,然后是n个数据,即n个要停的层的数据。

电梯开始在0层,上一层需要6秒,下一层需要4秒,停一次需要5秒。电梯最后不需要回到0层。

问题是把所有人都送到各层总共需要多少时间。

AC程序如下:

/* HDU1008 Elevator */

#include <stdio.h>
//#include <stdlib.h>

#define MAXN 100

int main(void)
{
    int n, stop[MAXN+1], count, i;
    int currposit;

    while(scanf("%d", &n) != EOF) {
        // 判断结束条件
        if(n == 0)
            break;

        // 读入数据
        for(i=0; i<n; i++)
            scanf("%d", &stop[i]);

        // 计算
        count = 0;
        currposit = 0;  // 电梯开始在0层
        for(i=0; i<n; i++) {
            if(stop[i] > currposit)
                count += (stop[i] - currposit) * 6;
            else
                count += (currposit - stop[i]) * 4;
            count += 5;

            currposit = stop[i];
        }

        // 输出结果
        printf("%d\n", count);
    }

    return 0;
}
时间: 2024-08-08 00:02:21

HDU1008 Elevator的相关文章

解题报告:hdu1008 Elvator

2017-09-07 19:30:22 writer:pprp 比较顺利,最近生活出现了各种问题, 发生了很多矛盾,我要耐下心来,最重要的不是努力不努力,而是选择 希望我能处理好人际关系还有学业上的压力. /* @theme: hdu1008 Elevator @writer:pprp @begin:21:37 @end:19:30 @declare:水题 @data:2017/9/7 */ #include <bits/stdc++.h> using namespace std; int m

HDU1008:Elevator

Elevator Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 42155    Accepted Submission(s): 23093 Problem Description The highest building in our city has only one elevator. A request list is mad

Elevator

Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u Description 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 s

hdu 1008 elevator

#include<iostream> #include<stdio.h> #include<math.h> #include<algorithm> using namespace std; int main() { int n; while(~scanf("%d",&n)&&n!=0) { int a,b; a=0; int ans=0; for(int i=0;i<n;i++) { scanf("

poj 2392 Space Elevator (多重背包)

Space Elevator Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 8110   Accepted: 3843 题目大意  :一群牛要上天  用一些石块堆塔  给出石块的种类  及其每个种类的数量 和该种石块能出现的最高高度  和每种石块的数量 求怎么摆放才能堆得最高 多重背包模板题.... 将所有石块排序  把高度低的放下面 #include<iostream> #include<cstdio>

POJ2392Space Elevator(贪心+背包)

Space Elevator Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 9970   Accepted: 4738 Description The cows are going to space! They plan to achieve orbit by building a sort of space elevator: a giant tower of blocks. They have K (1 <= K <

poj 2392 Space Elevator(多重背包+先排序)

Description The cows are going to space! They plan to achieve orbit by building a sort of space elevator: a giant tower of blocks. They have K (1 <= K <= 400) different types of blocks with which to build the tower. Each block of type i has height h

XTUOJ 1206 Dormitory&#39;s Elevator

Dormitory's Elevator Time Limit : 1000 MS   Memory Limit : 65536 KB Problem Description The new dormitory has N(1≤N≤100000) floors and M(1≤M≤100000)students. In the new dormitory, in order to save student's time as well as encourage student exercise,

1008. Elevator

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 seco