题解 CF1415A 【Prison Break】

Griseo_nya

2021-02-07 17:00:22

Solution

这道题读完题后,我们发现题中囚犯只能横竖左右行走。那么很容易想到从四个角开始走,四个里面总有一个用时最长。 那么代码...就放在下面了...呢。 ```cpp #include<bits/stdc++.h> using namespace std; #define int long long int work(int n,int m,int r,int c){ //判断函数 int tot=0LL; tot=max(tot,(abs(r-1)+abs(c-1))); //从左上角走 tot=max(tot,(abs(r-1)+abs(c-m))); //从左下角走 tot=max(tot,(abs(r-n)+abs(c-1))); //从右上角走 tot=max(tot,(abs(r-n)+abs(c-m))); //从右下角走 return tot; } #undef int int main(){ #define int long long int t; scanf("%lld",&t); for(int i=1;i<=t;i++){ int n,m,r,c; scanf("%lld%lld%lld%lld",&n,&m,&r,&c); printf("%lld\n",work(n,m,r,c)); //扫进去并判断 } return 0; } ```