想了个办法蛮力求解没超时也没爆内存,但是四个点不通过且无法Debug。
查看原帖
想了个办法蛮力求解没超时也没爆内存,但是四个点不通过且无法Debug。
386393
QS0x01楼主2020/9/29 11:53

如题,请求巨佬们抽空帮忙看看是不是我的输出格式有问题还是逻辑问题。

#include <bits/stdc++.h>
using namespace std;

struct box      //单链表结构定义
{
    int i, j;
    long long k;
    box *next;
};

void operator1(box *&r)
{
    int i, j, k;
    cin >> i >> j >> k;

    r->next = new box[1];
    r = r->next;
    r->next = NULL;

    r->i = i;
    r->j = j;
    r->k = k;
}

void operator2(box *p)
{
    int i, j;
    cin >> i >> j;

    box *q = p;

    while (q->next != NULL && q->i != i && q->j != j)
    {
        q = q->next;
    }

    cout << q->k << endl;
}

int main()
{
    int n, q, o;

    cin >> n >> q;

    box *p = new box[1];    //队头指针
    box *r = p;     //队尾指针

    p->next = NULL;

    for (int f = 0; f < q; f++)
    {
        cin >> o;

        if (o == 1)
        {
            operator1(r);
        }
        if (o == 2)
        {
            operator2(p);
        }
    }

    return 0;
}
2020/9/29 11:53
加载中...