QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#497598#7670. MessengerMax_s_xaMWA 22ms11128kbC++144.8kb2024-07-29 14:41:052024-07-29 14:41:05

Judging History

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

  • [2024-07-29 14:41:05]
  • 评测
  • 测评结果:WA
  • 用时:22ms
  • 内存:11128kb
  • [2024-07-29 14:41:05]
  • 提交

answer

#include <iostream>
#include <algorithm>
#include <cmath>
#include <iomanip>

typedef long long ll;
typedef double lf;

// #define DEBUG 1
struct IO
{
    #define MAXSIZE (1 << 20)
    #define isdigit(x) (x >= '0' && x <= '9')
    char buf[MAXSIZE], *p1, *p2;
    char pbuf[MAXSIZE], *pp;
    #if DEBUG
    #else
    IO() : p1(buf), p2(buf), pp(pbuf) {}
    ~IO() {fwrite(pbuf, 1, pp - pbuf, stdout);}
    #endif
    #define gc() (p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, MAXSIZE, stdin), p1 == p2) ? ' ' : *p1++)
    #define blank(x) (x == ' ' || x == '\n' || x == '\r' || x == '\t')

    template <typename T>
    void Read(T &x)
    {
        #if DEBUG
        std::cin >> x;
        #else
        bool sign = 0; char ch = gc(); x = 0;
        for (; !isdigit(ch); ch = gc())
            if (ch == '-') sign = 1;
        for (; isdigit(ch); ch = gc()) x = x * 10 + (ch ^ 48);
        if (sign) x = -x;
        #endif
    }
    void Read(char *s)
    {
        #if DEBUG
        std::cin >> s;
        #else
        char ch = gc();
        for (; blank(ch); ch = gc());
        for (; !blank(ch); ch = gc()) *s++ = ch;
        *s = 0;
        #endif
    }
    void Read(char &c) {for (c = gc(); blank(c); c = gc());}

    void Push(const char &c)
    {
        #if DEBUG
        putchar(c);
        #else
        if (pp - pbuf == MAXSIZE) fwrite(pbuf, 1, MAXSIZE, stdout), pp = pbuf;
        *pp++ = c;
        #endif
    }
    template <typename T>
    void Write(T x)
    {
        if (x < 0) x = -x, Push('-');
        static T sta[35];
        int top = 0;
        do sta[top++] = x % 10, x /= 10; while (x);
        while (top) Push(sta[--top] ^ 48);
    }
    template <typename T>
    void Write(T x, char lst) {Write(x), Push(lst);}
} IO;
#define Read(x) IO.Read(x)
#define Write(x, y) IO.Write(x, y)
#define Put(x) IO.Push(x)

using namespace std;

const int MAXN = 5e4 + 10;
const lf eps = 1e-8;

int n, m;

struct Point
{
    lf x, y;
    Point(lf _x = 0, lf _y = 0) : x(_x), y(_y) {}
    Point operator + (const Point &u) const { return Point(x + u.x, y + u.y); }
    Point operator - (const Point &u) const { return Point(x - u.x, y - u.y); }
    Point operator * (const lf &u) const { return Point(x * u, y * u); }
    Point operator / (const lf &u) const { return Point(x / u, y / u); }
};
inline lf sqr(const lf &x) { return x * x; }
inline lf dist(const Point &u) { return sqrt(sqr(u.x) + sqr(u.y)); }
inline lf dot(const Point &u, const Point &v) { return u.x * v.x + u.y * v.y; }
inline lf det(const Point &u, const Point &v) { return u.x * v.y - u.y * v.x; }
inline lf dist(const Point &x, const Point &y, const Point &u)
{
    lf ans = min(dist(x - u), dist(y - u));
    lf Dot = dot(u - x, y - x), d2 = dist(y - x);
    if (Dot > 0 && Dot < d2 * d2) ans = min(ans, abs(det(y - x, u - x)) / d2);
    return ans;
}

Point a[MAXN], b[MAXN], ia[MAXN], ib[MAXN];
Point c[MAXN], ic[MAXN];
lf da[MAXN], db[MAXN], dc[MAXN];

inline bool Check(lf x)
{
    lf dt = 0; int tot = 0;
    for (int i = 2; i <= m; i++)
    {
        if (dt + db[i] <= x) { dt += db[i]; continue; }
        Point tmp = b[i - 1];
        b[i - 1] = b[i - 1] + ib[i] * (x - dt), db[i] -= x - dt;
        lf ta = 0, tb = 0;
        c[tot = 1] = b[i - 1] - a[1];
        for (int u = 2, v = i; u <= n && v <= m;)
            if (tb + db[v] < ta + da[u])
            {
                tot++, ic[tot] = (u > n ? ib[v] : ib[v] - ia[u]), dc[tot] = tb + db[v] - max(tb, ta), c[tot] = c[tot - 1] + ic[tot] * dc[tot];
                tb += db[v], v++;
            }
            else
            {
                tot++, ic[tot] = ib[v] - ia[u], dc[tot] = ta + da[u] - max(tb, ta), c[tot] = c[tot - 1] + ic[tot] * dc[tot];
                ta += da[u], u++;
            }
        b[i - 1] = tmp, db[i] += x - dt;
        break;
    }
    lf mn = 1e18;
    for (int i = 2; i <= tot; i++) mn = min(mn, dist(c[i - 1], c[i], Point(0, 0)));
    return mn < x || abs(mn - x) < eps;
}

int main()
{
    // freopen("A.in", "r", stdin);
    // freopen("A.out", "w", stdout);
    #if DEBUG
    #else
    ios::sync_with_stdio(0), cin.tie(0);
    #endif
    Read(n);
    for (int i = 1; i <= n; i++) Read(a[i].x), Read(a[i].y);
    for (int i = 2; i <= n; i++) ia[i] = a[i] - a[i - 1], da[i] = dist(ia[i]), ia[i] = ia[i] / da[i];
    Read(m);
    for (int i = 1; i <= m; i++) Read(b[i].x), Read(b[i].y);
    lf sum = 0;
    for (int i = 2; i <= m; i++) ib[i] = b[i] - b[i - 1], db[i] = dist(ib[i]), ib[i] = ib[i] / db[i], sum += db[i];

    lf l = 0, r = sum, mid;
    if (dist(b[m] - a[1]) - sum > eps) return cout << "impossible\n", 0;
    while (r - l > eps)
    {
        mid = (l + r) / 2;
        if (Check(mid)) r = mid;
        else l = mid;
    }
    cout << fixed << setprecision(10) << l << "\n";
    return 0;
}

詳細信息

Test #1:

score: 100
Accepted
time: 1ms
memory: 10464kb

input:

2
0 0
0 10
2
4 10
4 0

output:

3.9999999851

result:

ok correct

Test #2:

score: 0
Accepted
time: 2ms
memory: 10064kb

input:

2
0 0
1 0
3
2 0
3 0
3 10

output:

4.9999999492

result:

ok correct

Test #3:

score: 0
Accepted
time: 1ms
memory: 9808kb

input:

2
0 30000
0 0
2
0 0
30000 0

output:

impossible

result:

ok correct

Test #4:

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

input:

2
0 30000
0 0
2
30000 0
0 0

output:

0.0000000000

result:

ok correct

Test #5:

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

input:

2
30000 0
0 0
2
30000 30000
0 30000

output:

impossible

result:

ok correct

Test #6:

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

input:

2
30000 0
0 0
2
0 30000
30000 30000

output:

29999.9999999864

result:

ok correct

Test #7:

score: -100
Wrong Answer
time: 22ms
memory: 11128kb

input:

50000
0 0
1 0
1 1
2 1
2 2
3 2
3 3
4 3
4 4
5 4
5 5
6 5
6 6
7 6
7 7
8 7
8 8
9 8
9 9
10 9
10 10
11 10
11 11
12 11
12 12
13 12
13 13
14 13
14 14
15 14
15 15
16 15
16 16
17 16
17 17
18 17
18 18
19 18
19 19
20 19
20 20
21 20
21 21
22 21
22 22
23 22
23 23
24 23
24 24
25 24
25 25
26 25
26 26
27 26
27 27
28 ...

output:

1.4142135517

result:

wrong answer read 1.414213551700 but expected 3.313708498985