码迷,mamicode.com
首页 > 其他好文 > 详细

CodeForces 339B Xenia and Ringroad(水题模拟)

时间:2016-07-08 15:15:56      阅读:305      评论:0      收藏:0      [点我收藏+]

标签:

题意:给定 n 个地方,然后再给 m 个任务,每个任务必须在规定的地方完成,并且必须按顺序完成,问你最少时间。

析:没什么可说的,就是模拟,记录当前的位置,然后去找和下一个位置相差多长时间,然后更新当前位置即可。

代码如下:

#include <bits/stdc++.h>

using namespace std;
const int maxn = 1e5 + 5;
typedef long long LL;

int main(){
    int n, m, x;
    while(cin >> n >> m){
        LL ans = 0;
        int pos = 1;
        for(int i = 0; i < m; ++i){
            cin >> x;
            if(x == pos)  continue;
            if(x > pos){
                ans += x - pos;
            }
            else ans += x + n - pos;
            pos = x;
        }
        cout << ans << endl;
    }
    return 0;
}

 

CodeForces 339B Xenia and Ringroad(水题模拟)

标签:

原文地址:http://www.cnblogs.com/dwtfukgv/p/5653370.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!