• 博客园logo
  • 会员
  • 众包
  • 新闻
  • 博问
  • 闪存
  • 赞助商
  • HarmonyOS
  • Chat2DB
    • 搜索
      所有博客
    • 搜索
      当前博客
  • 写随笔 我的博客 短消息 简洁模式
    用户头像
    我的博客 我的园子 账号设置 会员中心 简洁模式 ... 退出登录
    注册 登录
dwtfukgv
博客园    首页    新随笔    联系   管理    订阅  订阅
CodeForces 339B Xenia and Ringroad(水题模拟)

题意:给定 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;
}

 

posted on 2016-07-08 14:53  dwtfukgv  阅读(688)  评论(0)    收藏  举报
刷新页面返回顶部
博客园  ©  2004-2025
浙公网安备 33010602011771号 浙ICP备2021040463号-3