题解:P14069 初遇

· · 题解

P14069 初遇

题意

给定两个数 A,B,开始时 A \gets a,B \gets b,每次操作可以使 A \gets A+B 或 B \gets A+B。如果在操作时一定会出现 A = n 或 B = n,输出 No,否则输出 Yes。

思路

观察测试点的特殊性质。

当 a = b 时

(手造)输入:
1
1 1 3

多推几个样例,发现当且只当 a = n 或 2a = n 或 3a = n 时(之后的操作最多只有一种可能会出现 A = n 或 B = n,一定有另外一种可能时 A \not= n 或 B \not= n。),输出 No,否则输出 Yes。

当a \not= b时
通过之前 a = b 的讨论,我们发现只当 a = n 或 2a = n (在第二次操作时,因为 a \not= b,已经有两种结果不同的方案了)时输出 No,否则输出 Yes。

注意开始时 a = n 或 b = n 的情况

Code

AC记录
蒟蒻不怎么会写代码,喷轻点

code
#include<bits/stdc++.h>
using namespace std;
int T,a,n,b;
signed main(){
    cin>>T;//别忘了是多测
    while(T--){
        cin>>a>>b>>n;
        if(a==n||b==n||a+b==n||(a==b&&n==3*a))cout<<"No\n";//注意只有在 a=b 时才要判断 n 是否等于 3*a
        else cout<<"Yes\n";
    }
}

完结撒花