连求两题

题目总版

沐咕 @ 2024-11-08 21:34:30

#include <bits/stdc++.h>
using namespace std;
long long a, b;
set<long long> s;
int main()
{
    cin >> a >> b;
    s.insert(a);
    s.insert(b);
    long long x = a, y = b;
    while (true)
    {
        if (s.find(abs(y - x)) != s.end())
            break;
        s.insert(abs(y - x));
        x = y;
        y = abs(y - x);
    }
    cout << s.size() << endl;
    return 0;
}

by 沐咕 @ 2024-11-08 21:34:45

好吧,其实只有一题(


by MLE_Automaton @ 2024-11-08 21:35:17

小s是啥


by 沐咕 @ 2024-11-08 21:36:33

@MLE_Automaton 存出现过的数字啊,set 不是自动去重吗?


by DDD_et @ 2024-11-08 21:37:34

@沐咕

求绝对值要分正负性讨论,每一步都得分


by MLE_Automaton @ 2024-11-08 21:37:36

@沐咕 我说的是题中的小s


by DDD_et @ 2024-11-08 21:37:55

@MLE_Automaton

应该是打错了……


by 沐咕 @ 2024-11-08 21:38:18

@MLE_Automaton 那是大 S,题目有问题(


by 沐咕 @ 2024-11-08 21:38:36

@DDD_et 能理解,能给个代码吗qwq


by ran_qwq @ 2024-11-08 21:38:42

@沐咕 y = abs(y - x); 的y已经被赋值成x了


by DDD_et @ 2024-11-08 21:38:58

@沐咕

重复的条件是有两个相邻的数在以前也曾相邻的出现过


| 下一页