D题错麻了,有没有佬帮忙看看

// 总体思路是先凑出1 2 4 8 16.....直到乘2大于目标数后停止
// 然后用最大值加之前操作的序列,序列为1 2 4 8 ...,所以一定操作次数后一定可以配成目标数字
#include <bits/stdc++.h>
using namespace std;
const int inf = 0x3f3f3f3f;
#define kuaidu ios::sync_with_stdio(false), cin.tie(0), cout.tie(0)
#define PII pair<int, int>
#define endl '\n'
#define PI acos(-1)
#define int long long
vector<pair<int, PII>> v;
signed main()
{
    kuaidu;
    int T;
    cin >> T;
    while (T--)
    {
        int x, y;
        cin >> x >> y;
        if (x > y)
            swap(x, y);
        if (y % x == 0 || x == 1 || y == 1)
        {
            cout << 0 << endl;
            continue;
        }

        v.clear();
        int res = x * y / __gcd(x, y); //目标数字
        multiset<int> mu;
        int ans = 0;
        mu.insert(x), mu.insert(y);
        v.push_back({1, {x, y}}), v.push_back({1, {x, y}});
        mu.insert(1), mu.insert(1); //先把两个1插进去
        ans += 2;
        int now = 1;
        while (now * 2 <= res)
        {
            v.push_back({2, {now, now}}), v.push_back({2, {now, now}});
            ans += 2;
            now *= 2;
            mu.insert(now), mu.insert(now);
        }
        now = *mu.rbegin();
        while (now < res)
        {
            int xu = res - now;
            auto it = mu.lower_bound(xu);
            if (now + *it > res)
                it--;
            ans++;
            v.push_back({2, {*it, now}});
            mu.insert(now + *it);
            now = *mu.rbegin();
        }
        cout << ans << endl;
        for (auto x : v)
        {
            cout << x.first << " " << x.second.first << " " << x.second.second << endl;
        }
    }
}


全部评论
后面的没仔细看,但是一开始插入1显然不对吧,一开始插入的只能是gcd(x,y)吧,怎么能一开始就插入1呢?如果初始x = 2,y =4,那1又是哪来的呢?
点赞 回复 分享
发布于 2024-01-27 13:12 河南

相关推荐

Rena1ssanc...:对的,要是面评没太烂,勤更新简历等捞就行了,腾讯可以无限复活
点赞 评论 收藏
分享
叶扰云倾:进度更新,现在阿里云面完3面了,感觉3面答得还行,基本都答上了,自己熟悉的地方也说的比较细致,但感觉面试官有点心不在焉不知道是不是不想要我了,求阿里收留,我直接秒到岗当阿里孝子,学校那边的房子都退租了,下学期都不回学校,全职猛猛实习半年。这种条件还不诱人吗难道 然后现在约到了字节的一面和淘天的复活赛,外加猿辅导。华为笔试完没动静。 美团那边之前投了个base广州的,把我流程卡麻了,应该是不怎么招人,我直接简历挂了,现在进了一个正常的后端流程,还在筛选,不知道还有没有hc。
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务