炸掉 int 会 RE?
  • 板块灌水区
  • 楼主longlong_int
  • 当前回复5
  • 已保存回复5
  • 发布时间2024/7/24 11:36
  • 上次更新2024/7/24 12:59:31
查看原帖
炸掉 int 会 RE?
1059747
longlong_int楼主2024/7/24 11:36

B2001,数据量到了 101810^{18},会炸 int.但是炸 int 不是 WA 吗?为什么会 RE?

请欣赏我写的代码

#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
#include <algorithm>
#include <cmath>
#include <vector>
#include <queue>
typedef long long ll;
#define inf 0x7fffffffffffffff
using namespace std;

template<typename _ElementType>
class Operation
{
    public:
        _ElementType element;
        _ElementType anotherElement;
        _ElementType result;

        void getElementFromKeyboard()
        {
            cin >> element;
        }

        void getElementFromVariable(const _ElementType& x)
        {
            element = x;
        }

        void getAnotherElementFromKeyboard()
        {
            cin >> anotherElement;
        }

        void getAnotherElementFromVariable(const _ElementType& x)
        {
            anotherElement = x;
        }

        void doOperation()
        {
            result = element + anotherElement;
        }

        void putResultToScreen()
        {
            cout << result << endl;
        }

        void putResultToVariable(const _ElementType& x)
        {
            x = result;
        }
};

template<typename T>
class PutToScreen // 高效的输出队列
{
    private:
        queue<T> outputQueue; // 等待输出的内容
    public:
        void putElementInQueue(T x) // 待输出队列中加入元素
        {
            outputQueue.push(x);
        }

        void putElementsInQueue(T* x, int n)
        {
            for (int i = 0; i < n; i++)
            {
                outputQueue.push(x[i]);
            }
        }

        void printQueue()
        {
            while (!outputQueue.empty())
            {
                cout << outputQueue.front() << " ";
                outputQueue.pop();
            }
            cout << endl;
        }
};

template<typename T>
class GetFromScreen // 高效的输入队列
{
    private:
        queue<T> inputQueue; // 等待输入的内容
    public:
        void getElementFromQueue(T& x) // 从输入队列中取出元素
        {
            if (!inputQueue.empty())
            {
                x = inputQueue.front();
                inputQueue.pop();
            }
            else
            {
                throw runtime_error("Input queue is empty!");
            }
        }

        void getElementsFromQueue(T* x, int n)
        {
            for (int i = 0; i < n; i++)
            {
                getElementFromQueue(x[i]);
            }
        }

        void inputQueueFromStdin()
        {
            T x;
            while (cin >> x)
            {
                inputQueue.push(x);
            }
        }

        void inputQueueFromArray(T* x, int n)
        {
            for (int i = 0; i < n; i++)
            {
                inputQueue.push(x[i]);
            }
        }
};

int main()
{
    // 高效的输入输出类写完了,接下来用刚刚实现的 Operation 类做 A + B Problem
    Operation<ll> op;
    PutToScreen<ll> output;
    GetFromScreen<ll> input;

    input.inputQueueFromStdin(); // 从标准输入中读取输入队列

    // 输入 A 和 B
    int valueA, valueB;
    input.getElementFromQueue(valueA);
    input.getElementFromQueue(valueB);

    // 利用 Operation 类进行计算
    op.getElementFromVariable(valueA);
    op.getAnotherElementFromVariable(valueB);
    op.doOperation();


    // 输出结果
    output.putElementInQueue(op.result);
    output.printQueue();
    return 0;
}
2024/7/24 11:36
加载中...