QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#670331#7758. PainterzhcmmmCompile Error//C++202.2kb2024-10-23 21:20:192024-10-23 21:20:19

Judging History

你现在查看的是最新测评结果

  • [2024-10-23 21:20:19]
  • 评测
  • [2024-10-23 21:20:19]
  • 提交

answer

#include <bits/stdc++.h>
using pii = std::pair<int, int>;
#define x first
#define y second
 
pii operator-(pii a, pii b) {
    return {a.x - b.x, a.y - b.y};
}
i64 operator*(pii a, pii b) {
    return 1ll * a.x * b.x + 1ll * a.y * b.y;
}
i64 dis2(pii a, pii b) {
    auto p = a - b;
    return p * p;
}
bool Mid(int a, int b, int c) {
    return a <= b and b <= c;
}
 
struct Draw {
    std::string op = "";
    pii p1 = {0, 0};
    char col = '.';
    virtual bool Inside(pii p) = 0; // 纯虚函数
};
struct Circle : public Draw {
    int r = 0;
    bool Inside(pii p) { // 多态
        return dis2(p1, p) <= 1ll * r * r;
    }
};
struct Rectangle : public Draw {
    pii p2 = {0, 0};
    bool Inside(pii p) { // 多态
        return Mid(p1.x, p.x, p2.x) and Mid(p1.y, p.y, p2.y);
    }
};
 
int main() {
    std::ios_base::sync_with_stdio(false);
    std::cin.tie(nullptr);
 
    int qn;
    std::cin >> qn;
 
    std::vector<Draw *> a;
    for (int i = 0; i < qn; i++) {
        std::string op;
        std::cin >> op;
        if (op == "Circle") {
            Circle *p = new Circle();
            p->op = op;
            std::cin >> (p->p1.x) >> (p->p1.y);
            std::cin >> (p->r) >> (p->col);
 
            a.push_back(p);
        } else if (op == "Rectangle") {
            Rectangle *p = new Rectangle();
            p->op = op;
            std::cin >> (p->p1.x) >> (p->p1.y);
            std::cin >> (p->p2.x) >> (p->p2.y);
            std::cin >> (p->col);
 
            a.push_back(p);
        } else if (op == "Render") {
            pii p1, p2;
            std::cin >> p1.x >> p1.y;
            std::cin >> p2.x >> p2.y;
 
            std::vector res(p2.y - p1.y + 1, std::string(p2.x - p1.x + 1, '.'));
 
            for (auto p : a)
                for (int y = p1.y; y <= p2.y; y++)
                    for (int x = p1.x; x <= p2.x; x++)
                        if (p->Inside({x, y}))
                            res[y - p1.y][x - p1.x] = p->col;
 
            // 倒着输出
            for (int y = p2.y; y >= p1.y; y--) {
                std::cout << res[y - p1.y] << '\n';
            }
        }
    }
}

Details

answer.code:9:1: error: ‘i64’ does not name a type
    9 | i64 operator*(pii a, pii b) {
      | ^~~
answer.code:12:1: error: ‘i64’ does not name a type
   12 | i64 dis2(pii a, pii b) {
      | ^~~
answer.code: In member function ‘virtual bool Circle::Inside(pii)’:
answer.code:29:16: error: ‘dis2’ was not declared in this scope
   29 |         return dis2(p1, p) <= 1ll * r * r;
      |                ^~~~