QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#655351#9227. Henry the Plumberreal_sigma_teamWA 1ms4052kbC++233.5kb2024-10-19 03:09:292024-10-19 03:09:30

Judging History

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

  • [2024-10-19 03:09:30]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:4052kb
  • [2024-10-19 03:09:29]
  • 提交

answer

#include<bits/stdc++.h>

using namespace std;

constexpr int K = 3;
constexpr double PI = acos(-1);

using vec = std::array<double, K>;
using line = std::array<double, 3>;

vec operator+(const vec& a, const vec& b) {
    vec c;
    for (int i = 0; i < K; i++) {
        c[i] = a[i] + b[i];
    }
    return c;
}

vec operator-(const vec& a, const vec& b) {
    vec c;
    for (int i = 0; i < K; i++) {
        c[i] = a[i] - b[i];
    }
    return c;
}

double operator*(const vec& a, const vec& b) {
    double res = 0;
    for (int i = 0; i < K; i++) {
        res += a[i] * b[i];
    }
    return res;
}

double len(const vec& a) {
    return sqrt(a * a);
}

double angle(const vec& a, const vec& b) {
    vec c = a - b;
    return acos((a * a + b * b - c * c) / (2.0 * len(a) * len(b)));
}

line lin(const vec& norm, const vec& point) {
    line res;
    res[0] = norm[0] / len(norm);
    res[1] = norm[1] / len(norm);
    if (res[0] < 0 || (res[0] == 0 && res[1] < 0)) {
        res[0] *= -1;
        res[1] *= -1;
    }
    res[2] = -(res[0] * point[0] + res[1] * point[1]);
    return res;
}

bool operator==(const line& a, const line& b) {
    bool res = true;
    for (int i = 0; i < 3; i++) {
        res &= abs(a[i] - b[i]) < 1e-6;
    }
    return res;
}

bool colinear(const line& a, const line& b) {
    bool res = true;
    for (int i = 0; i < 2; i++) {
        res &= abs(a[i] - b[i]) < 1e-6;
    }
    return res;
}

double val(const line& a, const vec& b) {
    return a[0] * b[0] + a[1] * b[1] + a[2];
}

vec inter(line a, line b) {
    vec res;
    res[2] = 0;
    if (b[0] == 0) {
        swap(a, b);
    }
    if (a[0] != 0) {
        double coef = a[0] / b[0];
        for (int i = 0; i < K; i++) {
            a[i] -= b[i] * coef;
        }
    }
    res[1] = -a[2] / a[1];
    res[0] = -(res[1] * b[1] + b[2]) / b[0];
    return res;
}

void solve() {
    vec norm1, point1, norm2, point2;
    cin >> point1[0] >> point1[1] >> point1[2] >> norm1[0] >> norm1[1];
    cin >> point2[0] >> point2[1] >> point2[2] >> norm2[0] >> norm2[1];
    norm1[2] = 0;
    norm2[2] = 0;
    line l1 = lin(norm1, point1);
    line l2 = lin(norm2, point2);
    // cout << l1[0] << ' ' << l1[1] << ' ' << l1[2] << '\n';
    // cout << l2[0] << ' ' << l2[1] << ' ' << l2[2] << '\n';
    if (abs(val(l1, point2)) < 1e-8 && abs(val(l2, point1)) < 1e-8) {
        cout << "2\n";
        return;
    }
    if (colinear(l1, l2)) {
        cout << "4\n";
        return;
    }
    vec point = inter(l1, l2);
    // cout << point[0] << ' ' << point[1] << '\n';
    double l = -10000, r = 10000;
    while (r - l > 1e-10) {
        double m1 = (2 * l + r) / 3;
        double m2 = (l + 2 * r) / 3;
        point[2] = m1;
        double a1 = angle(point1 - point, point2 - point);
        point[2] = m2;
        double a2 = angle(point1 - point, point2 - point);
        if (a1 > a2) {
            r = m2;
        } else {
            l = m1;
        }
    }
    point[2] = l;
    double a = angle(point1 - point, point2 - point);
    if (point == point2 || point == point1) {
        cout << "4\n";
        return;
    }
    // cout << l << ' ' << a << ' ' << PI / 2 << '\n';
    if (a >= PI / 2 - 1e-8) {
        cout << "3\n";
        return;
    }
    cout << "4\n";
}

int main() {
    cin.tie(nullptr)->sync_with_stdio(false);
    cout << fixed << setprecision(30);
    int t;
    cin >> t;
    while (t--) {
        solve();
    }
}

详细

Test #1:

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

input:

2
-1 -1 3
1 1
2 2 3
2 2
5 5 1
3 0
7 6 -2
1 -2

output:

4
4

result:

wrong answer 2nd numbers differ - expected: '3', found: '4'