现在的位置: 首页 > 综合 > 正文

hdoj1008简单题

2014年03月04日 ⁄ 综合 ⁄ 共 277字 ⁄ 字号 评论关闭
#include<iostream>
using namespace std;

int main(){
    int m;
    int n;
    int pre;
    int total;    
    for(cin>>m; m != 0; cin>>m){
        cin>>n;
        pre = n;
        total = n * 6;
        total = total + 5;
        for(int i = 1; i < m; i++){            
            cin>>n;
            if(n > pre){
                total = total + 6 * (n - pre);
                pre = n;
            }else if(n < pre){
                total = total + 4 * (pre - n);
                pre = n;
            }
            total = total + 5;
        }
        cout<<total<<endl;
    }
}

抱歉!评论已关闭.