求指教代码的问题
查看原帖
求指教代码的问题
1527738
serendipity9876楼主2024/12/1 15:08
#include <iostream>
using namespace std;

struct Cut {
    int x1, y1, z1, x2, y2, z2;
};

int main() {
    int w, x, h;
    cin >> w >> x >> h;
    int q;
    cin >> q;
    const int MAX_CUTS = 100;
   
    Cut cuts[MAX_CUTS];
    for (int i = 0; i < q; ++i) {
        cin >> cuts[i].x1 >> cuts[i].y1 >> cuts[i].z1 >> cuts[i].x2 >> cuts[i].y2 >> cuts[i].z2;
    }

    // 计算原始立方体的体积
    long long total_volume = static_cast<long long>(w) * x * h;

    // 处理每次切割并减去被切割的体积
    for (int i = 0; i < q; ++i) {
        int dx = cuts[i].x2 - cuts[i].x1 + 1;
        int dy = cuts[i].y2 - cuts[i].y1 + 1;
        int dz = cuts[i].z2 - cuts[i].z1 + 1;
        long long cut_volume = static_cast<long long>(dx) * dy * dz;
        total_volume -= cut_volume; // 正确地从总体积中减去切割体积
    }

    // 输出剩余的小方块数量
    cout << total_volume << endl;

    return 0;
}

想问各位大佬:在VS上输入样例显示正确,但在洛谷里各个测试点全错,感谢感谢

2024/12/1 15:08
加载中...