CF1610A Anti Light's Cell Guessing 题解

· · 题解

题目传送门

题目分析

本题我们需要进行分类讨论:

  1. 如果 n = m = 1 ,则只有一种情况 (1,1) ,输出 0 。

  2. 如果 \min(n,m) =1 ,我们可以找到点 (1,1) ,这样任意一个点与其距离并不相同,输出 1 。

  3. 对于其他情况,我们可以找到点 (1,1) 与点 (n,1) ,可以得到答案均为 2 。

贴上代码

#include<iostream>
using namespace std;
int T;
int min(int a,int b){
    if(a>b) return b;
    else return a;
}
int main(){
    cin>>T;
    while(T--){
        register int n,m;
        cin>>n>>m;
        if(n==1&&m==1){
            cout<<"0\n";
            continue;
        }
        else if(min(n,m)==1){
            cout<<"1\n";
            continue;
        }
        else if(n>1&&m>1){
            cout<<"2\n";
            continue;
        }
    }
}