QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#808044#9869. Horizon ScanningHiraethsoul#WA 28ms3932kbC++232.8kb2024-12-10 16:36:432024-12-10 16:36:47

Judging History

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

  • [2024-12-10 16:36:47]
  • 评测
  • 测评结果:WA
  • 用时:28ms
  • 内存:3932kb
  • [2024-12-10 16:36:43]
  • 提交

answer

#include <bits/stdc++.h>

#define int long long

struct BaseVector2 : public std::pair<int, int>
{
#define x first
#define y second
    using std::pair<int, int>::pair;

    BaseVector2 operator-(BaseVector2 a) const
    {
        return BaseVector2(this->x - a.x, this->y - a.y);
    }
    int operator*(BaseVector2 a) const
    {
        return this->x * a.x + this->y * a.y;
    }
    int operator%(BaseVector2 a) const
    {
        return this->x * a.y - this->y * a.x;
    }
    friend std::istream &operator>>(std::istream &in, BaseVector2 &p)
    {
        return in >> p.x >> p.y;
    }
};

int dis2(BaseVector2 a, BaseVector2 b = BaseVector2(0, 0))
{
    BaseVector2 p = a - b;
    return p * p;
}

using Point = BaseVector2;
using Vector = Point;

int sgn(BaseVector2 p)
{
    if ((p.x < 0 or p.x == 0 and p.y > 0))
    {
        return true;
    }
    return false;
}
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;
        }
    }
    return sgn(p) < sgn(q);
}
const long double pi = acosl(-1.0);

long double getAngle(Point a, Point b, Point c)
{
    auto v1 = b - a, v2 = c - a;
    return atan2l(v1 % v2, v1 * v2);
}
void solve()
{
    int n, k;
    std::cin >> n >> k;
    std::vector<Point> t(n);
    for (int i = 0; i < n; ++i)
    {
        std::cin >> t[i];
    }
    std::sort(begin(t), end(t), polarCmp);
    std::vector<Point> s(2 * n + 1);
    for (int i = 0; i < n; ++i)
    {
        s[i] = t[i];
        s[i + n] = t[i];
    }

    long double ans = 0;
    std::vector<int> vis(2 * n + 1, 0);

    int i = 0, j = 0;
    int cnt = 0;
    while (i < n)
    {
        while (i < n and s[i + 1] % s[i] == 0)
        {
            if (vis[i])
            {
                --cnt;
                vis[i] = 0;
            }
            ++i;
        }
        if (vis[i])
        {
            vis[i] = 0;
            --cnt;
        }
        if (j <= i)
        {
            j = i + 1;
        }
        while (j < n + i and cnt < k)
        {
            ++cnt;
            vis[j] = 1;
            ++j;
        }
        if (cnt < k)
        {
            ans = 2 * pi;
        }
        else
        {
            long double val = getAngle(BaseVector2(0, 0), s[i], s[j - 1]);
            if (val < 0)
            {
                val += 2 * pi;
            }
            ans = std::max(ans, val);
        }
        ++i;
    }
    std::cout << std::fixed << std::setprecision(20) << ans << '\n';
}
signed main()
{
    std::ios::sync_with_stdio(0);
    std::cin.tie(0);

    int t;
    std::cin >> t;
    while (t--)
    {
        solve();
    }
}

详细

Test #1:

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

input:

5
1 1
0 1
8 2
1 0
1 1
0 1
-1 1
-1 0
-1 -1
0 -1
1 -1
4 2
-1 1
0 1
0 2
1 1
4 2
-1000000000 0
-998244353 1
998244353 1
1000000000 0
3 1
0 1
0 2
0 -1

output:

6.28318530717958647703
1.57079632679489661926
5.49778714378213816723
3.14159265459155197329
3.14159265358979323851

result:

ok 5 numbers

Test #2:

score: -100
Wrong Answer
time: 28ms
memory: 3932kb

input:

10000
16 1
-10 -6
-5 -6
-4 9
-2 5
-2 10
1 -7
1 -5
1 6
3 1
4 -9
6 -10
6 -3
6 1
8 -5
8 -4
9 -4
17 4
-9 2
-8 -4
-8 -3
-8 -1
-6 -2
-6 -1
-6 8
-5 -8
-5 10
-4 8
-2 -8
4 -9
4 0
5 -3
8 -5
9 -2
10 10
10 6
-7 2
-4 6
-2 -7
-2 -1
-1 7
1 -9
1 8
3 -4
7 -4
9 -2
14 3
-9 10
-8 -10
-8 -8
-6 -7
-6 -5
-1 -7
-1 -2
0 -1
...

output:

1.69299149748625167350
2.57486343606628689091
4.65275826725352046860
2.77263310738393677361
5.74276580690900232155
4.85769899102039198454
3.41989231259490458997
2.81279996208483885922
6.28318530717958647703
6.28318530717958647703
5.11728076666977328094
6.14678270277863904834
3.84208902353751959730
2...

result:

wrong answer 42nd numbers differ - expected: '6.2831853', found: '6.2599337', error = '0.0037006'