您的位置:首页 > 其它

HDU Elevator

2016-03-13 00:18 253 查看

HDU Elevator

题目传送门:http://acm.hdu.edu.cn/showproblem.php?pid=1008

本题没有什么特别的技巧,唯一值得注意的是两层楼相同时需要处理,不要单纯使用if…else if….else if….,不要少考虑情况,逻辑要严密,就这么多。

#include<stdio.h>
#include<string.h>
//#define LOCAL
using namespace std;
int main(){
#ifdef LOCAL
freopen("input.txt","r",stdin);
#endif // LOCAL
int current=0;
const int uptime=6,downtime=4,stoptime=5;
int sumtime=0;
int N=0;
int a=0;
while(scanf("%d",&N)!=EOF){
if(N==0)
break;
for(int i=0;i<N;i++){
scanf("%d",&a);
if(a>current)
sumtime+=(a-current)*uptime+stoptime;
//else if(a<current) 典型错误
else
sumtime+=(current-a)*downtime+stoptime;
current=a;
}
printf("%d\n",sumtime);
current=0;
sumtime=0;
}
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: