跳过正文
题解:P12418 【MX-X12-T1】「ALFR Round 5」地铁

题解:P12418 【MX-X12-T1】「ALFR Round 5」地铁

xyx404
作者
xyx404
Have a nice day.

封面

{% link 洛谷文章链接,xyx404,https://www.luogu.com.cn/article/jfgn4oek %}

思路:
#

通过分析,可以发现:

  • 当 $n$ 和 $m$ 中有一个为 $1$ 时,只用一条线就可以,答案为 $1$。
  • 当 $n$ 和 $m$ 中没有一个为 $1$ 时,当 $n

如果还是无法理解,可以看看图片。

代码:
#

#include<bits/stdc++.h>
using namespace std;
#define LL long long
#define itn int
#define ull unsigned long long
int T;
int main(){
	cin>>T;
	while(T--){
		int n,m;
		cin>>n>>m;
		if(n==1||m==1){
			cout<<"1\n";
		}
		else{
			cout<<min(n,m)+1<<"\n";
		}
	}
	return 0;
}