HDU Elevator

来源:互联网 发布:指导生活的算法mobi 编辑:程序博客网 时间:2024/05/21 06:56

HDU Elevator

题目传送门:http://acm.hdu.edu.cn/showproblem.php?pid=1008
本题没有什么特别的技巧,唯一值得注意的是两层楼相同时需要处理,不要单纯使用if…else if….else if….,不要少考虑情况,逻辑要严密,就这么多。

#include<stdio.h>#include<string.h>//#define LOCALusing 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;}
0 0
原创粉丝点击