Codeforces Round #687 (Div. 2, based on Technocup 2021 Elimination Round 2) A. Prison Break
阅读原文时间:2022年06月12日阅读:1

  • 题意:有一张\(n\)x\(m\)的图,图中每个点都关押着罪犯,在坐标\((r,c)\)处有一个出口,每名罪犯每秒可以可以像上下最有移动一个单位或者不动,问所有罪犯能够逃离监狱的最少时间.

  • 题解:直接算四个顶点到出口的值求个最大即可.

  • 代码:

    #include
    #define ll long long
    #define fi first
    #define se second
    #define pb push_back
    #define me memset
    #define rep(a,b,c) for(int a=b;a<=c;++a) #define per(a,b,c) for(int a=b;a>=c;--a)
    const int N = 1e6 + 10;
    const int mod = 1e9 + 7;
    const int INF = 0x3f3f3f3f;
    using namespace std;
    typedef pair PII;
    typedef pair PLL;

    int t;
    int n,m,r,c;

    int main() {
    ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    cin>>t;
    while(t--){
    cin>>n>>m>>r>>c;

        ll cnt1=r-1+c-1;
        ll cnt2=n-r+c-1;
        ll cnt3=r-1+m-c;
        ll cnt4=n-r+m-c;
    ll ans=max(cnt1,cnt2);
    ans=max(ans,cnt3);
    cout&lt;&lt;max(ans,cnt4)&lt;&lt;'\n';
    } return 0;

    }