QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#649562#9434. Italian CuisineLongvuWA 1ms5984kbC++145.8kb2024-10-18 02:10:072024-10-18 02:10:08

Judging History

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

  • [2024-10-18 02:10:08]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:5984kb
  • [2024-10-18 02:10:07]
  • 提交

answer

/**
 *    author:  longvu
 *    created: 10/17/24 21:39:48
**/
#include<bits/stdc++.h>

using namespace std;

#define int long long
#define ld long double
#define sz(x) ((int)x.size())
#define all(x) (x).begin(), (x).end()
const int INF = numeric_limits<int>::max();
const int nax = (int)(2010001);
const int mod = 1e9 + 7;

template<class X, class Y>
bool maximize(X& x, const Y y) {
    if (y > x) {x = y; return true;}
    return false;
}
template<class X, class Y>
bool minimize(X& x, const Y y) {
    if (y < x) {x = y; return true;}
    return false;
}

struct Point {
    ld x, y;
};

using Vtor = Point;

Vtor make_vtor(Point a, Point b) {
    return {b.x - a.x, b.y - a.y};
}

int cross(Vtor a, Vtor b) {
    return a.x * b.y - a.y * b.x;
}

const ld Exp = (ld)(1e-12);
const ld pi = acos(-1);

struct Segment {
    Point a, b;
};

const ld delta = (ld)(0.00000005);

ld sqr(ld z) {
    return z * z;
}

ld cal_dist(Point a, Point b) {
    return sqrt(sqr(b.x - a.x) + sqr(b.y - a.y));
}

ld cal_min_dist_point_to_segment(Point z, Segment g) {
    ld res = INF;
    Point u = g.a, v = g.b;
    minimize(res, min(cal_dist(z, u), cal_dist(z, v)));
    if (abs(u.x - v.x) < Exp) {
        Point vec = {v.x - u.x, v.y - u.y};
        tuple<ld, ld, ld> lnp = {vec.x, vec.y, vec.x * z.x + vec.y * z.y};
        swap(vec.x, vec.y);
        vec.x *= -1;
        tuple<ld, ld, ld> ln = {vec.x, vec.y, vec.x * u.x + vec.y * u.y};
        Point g = {0, (get<2>(ln) * get<0>(lnp) - get<0>(ln) * get<2>(lnp)) / (get<0>(lnp) * get<1>(ln) - get<0>(ln) * get<1>(lnp))};
        // cout << setprecision(4) << xxed << get<0>(ln) << " " << get<1>(ln) << " " << get<2>(ln) << '\n';
        // cout << setprecision(4) << xxed << get<0>(lnp) << " " << get<1>(lnp) << " " << get<2>(lnp) << '\n';
        g.x = (get<2>(ln) - get<1>(ln) * g.x) / get<0>(ln);
        // cout << u.x << " " << u.y <<  " " << v.x << " " << v.y << '\n';
        Point t = g;
        maximize(t.x, min(u.x, v.x));
        minimize(t.x, max(u.x, v.x));
        maximize(t.y, min(u.y, v.y));
        minimize(t.y, max(u.y, v.y));
        if (abs(t.x - g.x) < Exp && abs(t.y - g.y) < Exp) {
            minimize(res, cal_dist(z, g));
        }
    } else {
        Point vec = {v.x - u.x, v.y - u.y};
        tuple<ld, ld, ld> lnp = {vec.x, vec.y, vec.x * z.x + vec.y * z.y};
        swap(vec.x, vec.y);
        vec.x *= -1;
        tuple<ld, ld, ld> ln = {vec.x, vec.y, vec.x * u.x + vec.y * u.y};
        Point g = {(get<2>(ln) * get<1>(lnp) - get<1>(ln) * get<2>(lnp)) / (get<1>(lnp) * get<0>(ln) - get<1>(ln) * get<0>(lnp)), 0};
        // cout << setprecision(4) << xxed << get<0>(ln) << " " << get<1>(ln) << " " << get<2>(ln) << '\n';
        // cout << setprecision(4) << xxed << get<0>(lnp) << " " << get<1>(lnp) << " " << get<2>(lnp) << '\n';
        g.y = (get<2>(ln) - get<0>(ln) * g.x) / get<1>(ln);
        // cout << u.x << " " << u.y <<  " " << v.x << " " << v.y << '\n';
        Point t = g;
        maximize(t.x, min(u.x, v.x));
        minimize(t.x, max(u.x, v.x));
        maximize(t.y, min(u.y, v.y));
        minimize(t.y, max(u.y, v.y));
        if (abs(t.x - g.x) < Exp && abs(t.y - g.y) < Exp) {
            minimize(res, cal_dist(z, g));
        }
    }
    return res;
}

Point a[nax];
int pre[nax];
int32_t main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int tt;
    cin >> tt;
    while (tt--) {
        int n;
        cin >> n;
        Point b;
        int d;
        cin >> b.x >> b.y >> d;
        vector<Point> memo;
        for (int i = 0; i < n; ++i) {
            cin >> a[i].x >> a[i].y;
            while (sz(memo) >= 2 && !cross(make_vtor(memo[sz(memo) - 2], memo.back()), make_vtor(memo.back(), a[i]))) {
                memo.pop_back();
            }
            memo.push_back(a[i]);
        }
        n = sz(memo);
        for (int i = 0; i < n; ++i) {
            a[i] = a[n + i] = memo[i];
        }
        if (n <= 2) {
            cout << 0 << '\n';
            continue;
        }
        for (int i = 0; i < 2 * n - 1; ++i) {
            pre[i] = cross(a[i], a[i + 1]);
            if (i) {
                pre[i] += pre[i - 1];
            }
        }
        auto ck = [&](Point x, Point y, Point z) {
            int sum = abs(cross(make_vtor(b, x), make_vtor(b, y))
                          + cross(make_vtor(b, y), make_vtor(b, z))
                          + cross(make_vtor(b, z), make_vtor(b, x)));
            int sump = abs(cross(make_vtor(b, x), make_vtor(b, y)))
                       + abs(cross(make_vtor(b, y), make_vtor(b, z)))
                       + abs(cross(make_vtor(b, z), make_vtor(b, x)));
            return sum != sump;
        };
        int j = 0, ans = 0;
        for (int i = 0; i < n; ++i) {
            j = i + 1;
            Vtor z = make_vtor(a[i], a[j + 1]);
            z.x *= -1;
            swap(z.x, z.y);
            ld A = z.x, B = z.y, C = - z.x * a[i].x - z.y * a[i].y
                                     , dist = abs(A * b.x + B * b.y + C) / sqrt(A * A + B * B);
            while (cross(make_vtor(a[i], b), make_vtor(a[i], a[j + 1])) < 0
                    && dist >= d) {
                j++;
                Vtor z = make_vtor(a[i], a[j + 1]);
                z.x *= -1;
                swap(z.x, z.y);
                A = z.x, B = z.y, C = - z.x * a[i].x - z.y * a[i].y
                                      , dist = abs(A * b.x + B * b.y + C) / sqrt(A * A + B * B);
            }
            assert(j < 2 * n);
            int sum = abs(pre[j - 1] - (!i ? 0 : pre[i - 1])
                          + cross(a[j], a[i]));
            cout << i << " " << j << " " << sum << '\n';
            maximize(ans, sum);
        }
        cout << ans << '\n';
    }
    return 0;
}

詳細信息

Test #1:

score: 0
Wrong Answer
time: 1ms
memory: 5984kb

input:

3
5
1 1 1
0 0
1 0
5 0
3 3
0 5
6
2 4 1
2 0
4 0
6 3
4 6
2 6
0 3
4
3 3 1
3 0
6 3
3 6
0 3

output:

0 1 0
1 3 5
2 3 0
3 4 0
5
0 3 24
1 3 12
2 4 6
3 4 0
4 5 0
5 8 24
24
0 1 0
1 2 0
2 3 0
3 4 0
0

result:

wrong answer 1st numbers differ - expected: '5', found: '0'