Elevator(hdoj 1008)

Problem 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 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

There are multiple test cases. Each case contains a
positive integer N, followed by N positive numbers. All the numbers in the input
are less than 100. A test case with N = 0 denotes the end of input. This test
case is not to be processed.

Output

Print the total time on a single line for each test
case.

Sample Input

1 2

3 2 3 1

0

Sample Output

17

41

 1 #include<stdio.h>/*一道水题,秒杀*/
 2 int main()
 3 {
 4     int N;
 5     while(scanf("%d",&N)==1)
 6     {
 7         if(N==0)
 8             break;
 9         int a[101],i,j,time=0,k;
10         a[0]=0;
11         for(i=1;i<=N;i++)
12             scanf("%d",&a[i]);
13         for(i=1;i<=N;i++)
14             time+=(a[i]-a[i-1]>0?(a[i]-a[i-1])*6:(a[i-1]-a[i])*4)+5;
15         printf("%d\n",time);
16     }
17 } 
时间: 2024-10-06 00:27:59

Elevator(hdoj 1008)的相关文章

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: 8701   Accepted: 4135 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(多重背包)

Space Elevator Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 9042   Accepted: 4296 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 <

UVA 12486 Space Elevator(数位DP)

题目pdf:http://acm.bnu.edu.cn/v3/external/124/12486.pdf 大致题意:求第n个不包含"4"和"13"为子串的数是多少 , n<= 1e18 思路:就是一般的数位DP,二分答案,对答案的数求数位DP算出此数以内有多少个满足条件的数 但是....居然答案爆long long,要用unsigned long long 才能过,就这个坑点 // 0 ms 0 KB 2633 B 2015-08-15 01:02:36 /

ZOJ 1008 Gnome Tetravex (DFS + 剪枝)

Gnome Tetravex 题目:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=8 题意:有N*N个方格,每个方格分为上下左右四个部分,每个部分填数字.现在要求重排方块,使得每两个有边相连的方块对应的数字相同. 思路:就是一个简单的搜索,我想了个剪枝,将上下左右四个方向上每个数字对应的是哪几个方块记录下来,但是这个剪枝并没有起很大的作用,还是T了.后来才发现,如果有很多个方块是相同的,会重复搜索,所以需要将相同的方块一起处

1008. 数组元素循环右移问题 (20) (ZJUPAT 数学)

题目链接:http://pat.zju.edu.cn/contests/pat-b-practise/1008 一个数组A中存有N(N>0)个整数,在不允许使用另外数组的前提下,将每个整数循环向右移M(M>=0)个位置,即将A中的数据由(A0 A1--AN-1)变换为(AN-M -- AN-1 A0 A1--AN-M-1)(最后M个数循环移至最前面的M个位置).如果需要考虑程序移动数据的次数尽量少,要如何设计移动的方法? 输入格式:每个输入包含一个测试用例,第1行输入N ( 1<=N&l

HDOJ 1163 Eddy&#39;s digital Roots(简单数论)

[思路]:http://blog.csdn.net/iamskying/article/details/4738838 求解思路: 现在分析一个问题,假设将十位数为a,个位数为b的一个整数表示为ab,则推导得 ab*ab = (a*10+b)*(a*10+b) = 100*a*a+10*2*a*b+b*b 根据上式可得:root(ab*ab) = a*a+2*a*b+b*b = (a+b)*(a+b);[公式一] 同理也可证得:root(ab*ab*ab) = (a+b)*(a+b)*(a+b)

HDOJ 题目4349 Xiao Ming&#39;s Hope(找规律)

Xiao Ming's Hope Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 1515    Accepted Submission(s): 1015 Problem Description Xiao Ming likes counting numbers very much, especially he is fond of co

hdoj 1097 A hard puzzle (找规律)

A hard puzzle                            T   ime Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 29231    Accepted Submission(s): 10494 Problem Description lcy gives a hard puzzle to feng5166,lwg,JG