首页 > 其他 > 详细

Codeforces Round #687 (Div. 2, based on Technocup 2021 Elimination Round 2) A. Prison Break

时间:2020-11-29 23:01:07      阅读:30      评论:0      收藏:0      [点我收藏+]

技术分享图片

  • 题意:有一张\(n\)x\(m\)的图,图中每个点都关押着罪犯,在坐标\((r,c)\)处有一个出口,每名罪犯每秒可以可以像上下最有移动一个单位或者不动,问所有罪犯能够逃离监狱的最少时间.
  • 题解:直接算四个顶点到出口的值求个最大即可.
  • 代码:
#include <bits/stdc++.h>
#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<int,int> PII;
typedef pair<ll,ll> 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<<max(ans,cnt4)<<‘\n‘;
	}
 
    return 0;
}

Codeforces Round #687 (Div. 2, based on Technocup 2021 Elimination Round 2) A. Prison Break

原文:https://www.cnblogs.com/lr599909928/p/14058168.html

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