PAT甲级1008 Elevator (20分)

PAT甲级1008 Elevator (20分)

题目:在这里插入图片描述
题目分析:刚看到题目以为是道dp问题,但仔细一看,这。。。
直接看AC代码吧,小学数学问题。

AC代码附上:

#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;


int main(){
    
    
    int n,sum=0,now=0,to;
    scanf("%d",&n);
    for(int i=0;i<n;i++){
    
    
        scanf("%d",&to);
        if(to>now){
    
    
            sum+=(to-now)*6;
        }else{
    
    
            sum+=(now-to)*4;
        }
        sum+=5;
        now=to;
    }
    printf("%d\n",sum);
    return 0;
}

猜你喜欢

转载自blog.csdn.net/weixin_43795683/article/details/104265865