QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#625578#7906. Almost ConvexflsCompile Error//C++205.0kb2024-10-09 19:58:462024-10-09 19:58:46

Judging History

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

  • [2024-10-09 19:58:46]
  • 评测
  • [2024-10-09 19:58:46]
  • 提交

answer

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

#define qmx(a,b) a<b?b:a
#define qmn(a,b) a>b?b:a
#define int long long
#define fr first
#define se second

template <class T, class G>
struct BaseVector2 {
    T x, y;
    constexpr BaseVector2() : BaseVector2(T{}, T{}) {}
    constexpr BaseVector2(T x, T y) : x{x}, y{y} {}

    // 运算
    constexpr BaseVector2 operator+(BaseVector2 a) const {
        return BaseVector2(x + a.x, y + a.y);
    }
    constexpr BaseVector2 operator-(BaseVector2 a) const {
        return BaseVector2(x - a.x, y - a.y);
    }
    constexpr BaseVector2 operator-() const {
        return BaseVector2(-x, -y);
    }
    constexpr G operator*(BaseVector2 a) const {
        return G(x) * a.x + G(y) * a.y;
    }
    constexpr G operator%(BaseVector2 a) const {
        return G(x) * a.y - G(y) * a.x;
    }
    constexpr BaseVector2 rotate() const {
        return BaseVector2(-y, x);
    }
    template<class Float>
    constexpr BaseVector2 rotate(Float theta) const {
        BaseVector2 b(cosl(theta), sinl(theta));
        return BaseVector2(x * b.x - y * b.y,
                           x * b.y + y * b.x);
    }
    constexpr friend BaseVector2 operator*(const T &a, BaseVector2 b) {
        return BaseVector2(a * b.x, a * b.y);
    }

    // 比较
    constexpr bool operator<(BaseVector2 a) const {
        if (x == a.x) {
            return y < a.y;
        }
        return x < a.x;
    }

    constexpr bool operator>(BaseVector2 a) const {
        if (x == a.x) {
            return y > a.y;
        }
        return x > a.x;
    }

    constexpr bool operator<=(BaseVector2 a) const {
        if (x == a.x) {
            return y <= a.y;
        }
        return x <= a.x;
    }

    constexpr bool operator>=(BaseVector2 a) const {
        if (x == a.x) {
            return y >= a.y;
        }
        return x >= a.x;
    }

    constexpr bool operator==(BaseVector2 a) const {
        return x == a.x and y == a.y;
    }

    constexpr bool operator!=(BaseVector2 a) const {
        return x != a.x or y != a.y;
    }

    // 输入输出
    friend std::istream &operator>>(std::istream &in, BaseVector2 &p) {
        return in >> p.x >> p.y;
    }
    friend std::ostream &operator<<(std::ostream &ot, BaseVector2 p) {
        return ot << '(' << p.x << ", " << p.y << ')';
    }
};

template <class T, class G>
G dis2(BaseVector2<T, G> a, BaseVector2<T, G> b = BaseVector2<T, G>(0, 0)) {
    BaseVector2<T, G> p = a - b;
    return p * p;
}
template <class T, class G>
auto dis(BaseVector2<T, G> a, BaseVector2<T, G> b = BaseVector2<T, G>(0, 0)) {
    return sqrtl(dis2(a, b));
}

template <class T, class G>
int sgn(BaseVector2<T, G> p) {
    if (p.x < 0 or p.x == 0 and p.y > 0) {
        return 1;
    } else
        return 0;
    // 以41象限为先
}

template <class Vector>
bool polarCmp(Vector p, Vector q) {
    if (sgn(p) == sgn(q)) {
        if (p % q == 0) {
            return dis2(p) < dis2(q);
        } else {
            return p % q > 0;
        }
    } else {
        return sgn(p) < sgn(q);
    }
}

using Point = BaseVector2<int, ll>;
using Vector = Point;
using PS = std::vector<Point>;

PS convex(PS ps) {
    std::sort(ps.begin(), ps.end());
    ps.erase(std::unique(ps.begin(), ps.end()), ps.end());

    const int n = ps.size();
    if (n <= 1) {
        return ps;
    }

    PS hull(n + 1);
    int k = -1;

    for (int i = 0; i < n; i++) {
        while (k >= 1 and (hull[k] - hull[k - 1]) % (ps[i] - hull[k]) <= 0) {
            k -= 1;
        }
        hull[++k] = ps[i];
    }

    for (int i = n - 2, m = k + 1; i >= 0; i--) {
        while (k >= m and (hull[k] - hull[k - 1]) % (ps[i] - hull[k]) <= 0) {
            k -= 1;
        }
        hull[++k] = ps[i];
    }

    assert(k >= 2);
    return hull.resize(k), hull;
}

inline bool belong(Point x, PS &st){
    for(auto pt : st){
        if(pt == x)
            return true;
    }
    return false;
}

inline PS calculate(PS &st, Point o){
    PS res;
    for(auto pt : st){
        if(pt != o){
            res.push_back(pt - o);
            //cerr << pt - o << endl;
        }
    }
    //cerr << endl;
    return res;
}

const int mxn = 2e3+3;

int n, ans;

PS p, convex_p, dcp;

int main(){
    cin >> n;
    p.resize(n);
    for(int i = 0 ; i < n ; i++)
        cin >> p[i];
    
    convex_p = convex(p);

    ans = 1;

    for(int i = 0 ; i < n ; i++){
        if(!belong(p[i], convex_p)){
            dcp = calculate(p, p[i]);
            sort(dcp.begin(), dcp.end(), polarCmp<Point>);
            for(int j = 1 ; j < dcp.size() ; j++){
                if(belong(dcp[j] + p[i], convex_p) && belong(dcp[j - 1] + p[i], convex_p))
                    ans++;
            }
            if(belong(dcp[dcp.size() - 1] + p[i], convex_p) && belong(dcp[0] + p[i], convex_p))
                ans++;
        }
    }

    cout << ans;
    return 0;
}

Details

answer.code:123:32: error: ‘ll’ was not declared in this scope
  123 | using Point = BaseVector2<int, ll>;
      |                                ^~
answer.code:123:34: error: template argument 2 is invalid
  123 | using Point = BaseVector2<int, ll>;
      |                                  ^
answer.code:124:16: error: ‘Point’ does not name a type
  124 | using Vector = Point;
      |                ^~~~~
answer.code:125:24: error: ‘Point’ was not declared in this scope
  125 | using PS = std::vector<Point>;
      |                        ^~~~~
answer.code:125:29: error: template argument 1 is invalid
  125 | using PS = std::vector<Point>;
      |                             ^
answer.code:125:29: error: template argument 2 is invalid
answer.code:125:17: error: ‘<expression error>’ in namespace ‘std’ does not name a type
  125 | using PS = std::vector<Point>;
      |                 ^~~~~~~~~~~~~
answer.code:127:1: error: ‘PS’ does not name a type
  127 | PS convex(PS ps) {
      | ^~
answer.code:157:20: error: ‘Point’ was not declared in this scope
  157 | inline bool belong(Point x, PS &st){
      |                    ^~~~~
answer.code:157:29: error: ‘PS’ was not declared in this scope
  157 | inline bool belong(Point x, PS &st){
      |                             ^~
answer.code:157:33: error: ‘st’ was not declared in this scope; did you mean ‘std’?
  157 | inline bool belong(Point x, PS &st){
      |                                 ^~
      |                                 std
answer.code:157:35: error: expression list treated as compound expression in initializer [-fpermissive]
  157 | inline bool belong(Point x, PS &st){
      |                                   ^
answer.code:165:8: error: ‘PS’ does not name a type
  165 | inline PS calculate(PS &st, Point o){
      |        ^~
answer.code:181:1: error: ‘PS’ does not name a type
  181 | PS p, convex_p, dcp;
      | ^~
cc1plus: error: ‘::main’ must return ‘int’
answer.code: In function ‘int main()’:
answer.code:185:5: error: ‘p’ was not declared in this scope
  185 |     p.resize(n);
      |     ^
answer.code:189:5: error: ‘convex_p’ was not declared in this scope; did you mean ‘ucontext_t’?
  189 |     convex_p = convex(p);
      |     ^~~~~~~~
      |     ucontext_t
answer.code:189:16: error: ‘convex’ was not declared in this scope
  189 |     convex_p = convex(p);
      |                ^~~~~~
answer.code:194:19: error: ‘belong’ cannot be used as a function
  194 |         if(!belong(p[i], convex_p)){
      |             ~~~~~~^~~~~~~~~~~~~~~~
answer.code:195:13: error: ‘dcp’ was not declared in this scope; did you mean ‘dup’?
  195 |             dcp = calculate(p, p[i]);
      |             ^~~
      |             dup
answer.code:195:19: error: ‘calculate’ was not declared in this scope
  195 |             dcp = calculate(p, p[i]);
      |                   ^~~~~~~~~
answer.code:196:51: error: ‘Point’ was not declared in this scope
  196 |             sort(dcp.begin(), dcp.end(), polarCmp<Point>);
      |                                                   ^~~~~
answer.code:198:26: error: ‘belong’ cannot be used as a function
  198 |                 if(belong(dcp[j] + p[i], convex_p) && belong(dcp[j - 1] + p[i], convex_p))
      |                    ~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
answer.code:198:61: error: ‘belong’ cannot be used as a function
  198 |                 if(belong(dcp[j] + p[i], convex_p) && belong(dcp[j - 1] + p[i], convex_p))
      |                                                       ~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
answer.code:201:22: error: ‘belong’ cannot be used as a function
  201 |             if(belong(dcp[dcp.size() - 1] + p[i], convex_p) && belong(dcp[0] + p[i], convex_p))
      |                ~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
answer.code:201:70: error: ‘belong’ cannot be used as a function
  201 |             if(belong(dcp[dcp.size() - 1] + p[i], convex_p) && belong(dcp[0] + p[i], convex_p))
      |                                                                ~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~