QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#622864#7906. Almost ConvexwpoemCompile Error//C++204.9kb2024-10-09 08:02:322024-10-09 08:02:34

Judging History

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

  • [2024-10-09 08:02:34]
  • 评测
  • [2024-10-09 08:02:32]
  • 提交

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 ll long long
#define i64 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, int>;
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);
        }
    }
    return res;
}

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;
}

詳細信息

answer.code:203:5: error: ‘cout’ does not name a type
  203 |     cout << ans;
      |     ^~~~
answer.code:204:5: error: expected unqualified-id before ‘return’
  204 |     return 0;
      |     ^~~~~~
answer.code:205:1: error: expected declaration before ‘}’ token
  205 | }
      | ^