QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#622880#7906. Almost ConvexwpoemWA 510ms3828kbC++205.1kb2024-10-09 08:16:012024-10-09 08:16:02

Judging History

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

  • [2024-10-09 08:16:02]
  • 评测
  • 测评结果:WA
  • 用时:510ms
  • 内存:3828kb
  • [2024-10-09 08:16:01]
  • 提交

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 main()
{
    int n, ans{1};
    cin >> n;
    PS p(n), convex_p, dcp;
    for (int i = 0; i < n; i++) {
        cin >> p[i];
    }

    convex_p = convex(p);

    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 = 0; j + 1 < 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) and std::size(dcp) > 1) {
                ans++;
            }
        }
    } //

    std::cout << ans;
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 3596kb

input:

7
1 4
4 0
2 3
3 1
3 5
0 0
2 4

output:

9

result:

ok 1 number(s): "9"

Test #2:

score: 0
Accepted
time: 0ms
memory: 3828kb

input:

5
4 0
0 0
2 1
3 3
3 1

output:

5

result:

ok 1 number(s): "5"

Test #3:

score: 0
Accepted
time: 0ms
memory: 3568kb

input:

3
0 0
3 0
0 3

output:

1

result:

ok 1 number(s): "1"

Test #4:

score: 0
Accepted
time: 0ms
memory: 3628kb

input:

6
0 0
3 0
3 2
0 2
1 1
2 1

output:

7

result:

ok 1 number(s): "7"

Test #5:

score: 0
Accepted
time: 0ms
memory: 3600kb

input:

4
0 0
0 3
3 0
3 3

output:

1

result:

ok 1 number(s): "1"

Test #6:

score: -100
Wrong Answer
time: 510ms
memory: 3652kb

input:

2000
86166 617851
383354 -277127
844986 386868
-577988 453392
-341125 -386775
-543914 -210860
-429613 606701
-343534 893727
841399 339305
446761 -327040
-218558 -907983
787284 361823
950395 287044
-351577 -843823
-198755 138512
-306560 -483261
-487474 -857400
885637 -240518
-297576 603522
-748283 33...

output:

30883

result:

wrong answer 1st numbers differ - expected: '718', found: '30883'