杭电acm1008 hdu-acm-1008解题报告
来源:互联网 发布:java类声明 编辑:程序博客网 时间:2024/05/30 23:49
题目地址:
点此打开题目地址
题目:
Elevator
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 43034 Accepted Submission(s): 23608
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.
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 23 2 3 10
Sample Output
1741
大意和思路:这个题的思路比较简单,当上一层楼的时候,每上一层楼用6个小时,电梯在楼层停留5个小时,每下一层楼电梯用4个小时;计上下楼的顺序是啊【n】;n<100;如果是上楼,时间是(a[i]-a[i-1])*6+5;下楼是(a[i]-a[i-1])*4+5;
代码:
#include<stdio.h>int t(int a,int b){return a>b?(a-b)*4+5:(b-a)*6+5;}main(){int i,j,k,m,n,T,a[110],time;while(scanf("%d",&T)&&T){for(i=0;i<T;i++)scanf("%d",&a[i]);time=0;time+=t(0,a[0]);for(i=1;i<T;i++)time+=t(a[i-1],a[i]);printf("%d\n",time);}}
0 0
- 杭电acm1008 hdu-acm-1008解题报告
- 杭电acm1012 hdu-acm-1012解题报告
- 杭电acm1013 hdu-acm-1013解题报告
- 杭电acm1014 hdu-acm-1014解题报告
- 杭电acm1017 hdu-acm-1017解题报告
- 杭电acm1019 hdu-acm-101解题报告
- 杭电acm1021 hdu-acm-1021解题报告
- 杭电acm1019 hdu-acm-101解题报告
- 杭电acm1056 hdu-acm-1056解题报告
- 杭电acm1232 hdu-acm-1232畅通工程解题报告
- 杭电acm2091 hdu-acm-2091空心三角形解题报告
- 杭电acm2089 hdu-acm-2089不要62解题报告
- 杭电Hdu 1008 Elevator解题报告
- 杭电acm2170hdu-acm-2170解题报告
- 杭电acm1406hdu-acm-1406解题报告
- 杭电ACM hdu 1171 Big Event in HDU 解题报告(母函数)
- 杭电ACM hdu 2110 Crisis of HDU 解题报告(母函数)
- 杭电acm1008 Elevator
- 使用OpenSessionInViewFilter解决lazy failed问题
- 技术总结--android篇(二)--布局的优化
- hd 2187 悼念512汶川大地震遇难同胞——老人是真饿了
- eclipse中的Java文件自动根据svn版本号生成注释
- abercrombie online italia the Japanese steel powerless because of the lack of new stadiums
- 杭电acm1008 hdu-acm-1008解题报告
- (c语法百题16)一元二次方程的实数根
- vetement hollister pas cher Sharon
- 对Mahout_"推荐算法"的初步认识(5)_研讨篇
- MD5 加密方法
- basket nike tn pas cher or with a towel
- Cocos2d-x 3.0心得(05)-音效管理
- Ray Ban France the captain closed the door after five people blocking up the plane took off more th
- 数据结构:点对之间最短距离--Floyd算法