首页 > 其他 > 详细

【Educational Codeforces Round 36 B】Browser

时间:2018-01-14 10:40:02      阅读:340      评论:0      收藏:0      [点我收藏+]

【链接】 我是链接,点我呀:)
【题意】


在这里输入题意

【题解】


分类在区间里面和左边、右边三种情况。
看看l的左边有没有标签、r的右边有没有标签。
就能做完了。

【代码】

#include <bits/stdc++.h>
using namespace std;

int n,pos,l,r;

int main(){
    #ifdef LOCAL_DEFINE
        freopen("rush_in.txt", "r", stdin);
    #endif
    ios::sync_with_stdio(0),cin.tie(0);

    cin >> n >> pos >>l>>r;
    int temp1 = 1000,temp2 = 1000;
    if (r!=n){
        temp2 = r-pos;
    }
    if (l!=1){
        temp1 = pos-l;
    }

    if (l<=pos&&pos<=r){

        if (temp1==1000 && temp2==1000) return cout<<0<<endl,0;
        int ans;
        if (temp1!=1000 && temp2!=1000){
            ans = min(temp1,temp2) + r-l;
            ans++;ans++;
        }else{
            ans = min(temp1,temp2);
            ans++;
        }
        cout << ans << endl;
    }else{
        int ans = 0;
        if (pos>r){
            ans+=pos-r;
            ans++;
            if (temp1!=1000){
                ans+=r-l;
                ans++;
            }
        }else{//pos<l
            ans+=l-pos;
            ans++;
            if (temp2!=1000){
                ans+=r-l;
                ans++;
            }
        }
        cout << ans << endl;
    }
    return 0;
}

【Educational Codeforces Round 36 B】Browser

原文:https://www.cnblogs.com/AWCXV/p/8282306.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!