首页 > 其他 > 详细

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

时间:2016-07-08 15:14:50      阅读:181      评论: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
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!