Elevator解题报告
2013-07-28 21:23
162 查看
题目摘要:The highest building in our cityhas only one elevator. A request list is made up with N positive numbers. Thenumbers denote at which floors the elevator will stop,
in specified order. Itcosts 6 seconds to move the elevator up one floor, and 4 seconds to move downone 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 fulfillthe requests on the list. The elevator is on the 0th floor at the beginning anddoes not have to return to the ground floor when the requests are fulfilled.
题目大意:电梯问题,一架电梯位于第0层,上升一层用6秒,下降一层用4秒,停在一层用5秒,给出一串命令求所用时间。
输入输出要求:
Input
There are multiple test cases. Each casecontains a positive integer N, followed by N positive numbers. All the numbersin the input are less than 100. A test case with N = 0 denotes the end ofinput. This test case is not to be
processed.
Output
Print the total time on a single line foreach test case.
输入输出样例:
Sample Input
1 2
3 2 3 1
0
Sample Output
17
41
解题思路:直接开一个数组,比较第i项和前一项的大小,然后加上相应的时间。
代码:
#include<iostream>
using namespace std;
int num[105];
int main()
{
int N;
num[0]=0;
while(cin>>N)
{
if(N==0)
return0;
else
{
int i;
int sum=0;
for(i=1;i<=N;i++)
{
cin>>num[i];
if(num[i]>num[i-1])
sum=sum+6*(num[i]-num[i-1])+5;
else if(num[i]==num[i-1])
sum=sum+5;
else if(num[i]<num[i-1])
sum=sum+4*(num[i-1]-num[i])+5;
}
cout<<sum<<endl;
}
}
return 0;
}
解题感想:水题一枚,不想多说。
in specified order. Itcosts 6 seconds to move the elevator up one floor, and 4 seconds to move downone 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 fulfillthe requests on the list. The elevator is on the 0th floor at the beginning anddoes not have to return to the ground floor when the requests are fulfilled.
题目大意:电梯问题,一架电梯位于第0层,上升一层用6秒,下降一层用4秒,停在一层用5秒,给出一串命令求所用时间。
输入输出要求:
Input
There are multiple test cases. Each casecontains a positive integer N, followed by N positive numbers. All the numbersin the input are less than 100. A test case with N = 0 denotes the end ofinput. This test case is not to be
processed.
Output
Print the total time on a single line foreach test case.
输入输出样例:
Sample Input
1 2
3 2 3 1
0
Sample Output
17
41
解题思路:直接开一个数组,比较第i项和前一项的大小,然后加上相应的时间。
代码:
#include<iostream>
using namespace std;
int num[105];
int main()
{
int N;
num[0]=0;
while(cin>>N)
{
if(N==0)
return0;
else
{
int i;
int sum=0;
for(i=1;i<=N;i++)
{
cin>>num[i];
if(num[i]>num[i-1])
sum=sum+6*(num[i]-num[i-1])+5;
else if(num[i]==num[i-1])
sum=sum+5;
else if(num[i]<num[i-1])
sum=sum+4*(num[i-1]-num[i])+5;
}
cout<<sum<<endl;
}
}
return 0;
}
解题感想:水题一枚,不想多说。
相关文章推荐
- hdoj-1008-Elevator(解题报告)
- pku 2392 space elevator 多重背包 dp 解题报告
- 1635 Space Elevator【解题报告】
- TYVJ 1086 Elevator 解题报告
- problem-1006 Elevator 解题报告
- hdu 1008 Elevator 的解题报告
- 1006-Elevator-解题报告
- Letter Combinations of a Phone Number解题报告
- 1093. Count PAT's (25)解题报告
- USACO Section 1.4 Mother's Milk 解题报告
- 20110719数据结构10级复习赛题级解题报告ccnuoj
- POJ 3528 Ultimate Weapon三维凸包(解题报告)
- LeetCode解题报告 --- Single Number II
- [Leetcode] 379. Design Phone Directory 解题报告
- POJ1426 Find The Multiple 解题报告
- HNU 省赛选拔热身赛City Merger解题报告
- Mango Weekly Training Round #3 解题报告
- [leetcode] 275. H-Index II 解题报告
- 【解题报告】 POJ 1113 Wall -- 求凸包周长
- Leetcode Distinct Subsequences 解题报告