zoukankan      html  css  js  c++  java
  • 【Educational Codeforces Round 36 B】Browser

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

    在这里输入题意

    【题解】

    分类在区间里面和左边、右边三种情况。 看看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;
    }
    
  • 相关阅读:
    MyBatis的缓存
    16年随笔
    linux 随笔
    Linux下启动Tomcat启动并显示控制台日志信息
    linux 连接工具
    Linux Tomcat重新启动
    SpringMVC 文件上传 MultipartFile
    spring @component
    mysql转型
    MyBatis传入参数
  • 原文地址:https://www.cnblogs.com/AWCXV/p/8282306.html
Copyright © 2011-2022 走看看