社区讨论

spj 提供

P9119[春季测试 2023] 圣诞树参与者 9已保存回复 11

讨论操作

快速查看讨论及其快照的属性,并进行相关操作。

当前回复
11 条
当前快照
1 份
快照标识符
@lo30m3l5
此快照首次捕获于
2023/10/23 22:50
2 年前
此快照最后确认于
2023/10/23 22:50
2 年前
查看原帖
RT,有锅的话 @ 我,我会尽快修。
CPP
#include <bits/stdc++.h>
#include "testlib.h"
using namespace std;
const int N = 1009;
#define double long double
struct node {
    double x, y;
} a[N];
inline double dist(int x, int y) {
    double dx = a[x].x - a[y].x, dy = a[x].y - a[y].y;
    return sqrtl(dx * dx + dy * dy);
}
int n, out[N], ans_out[N];
bool vis_out[N], vis_ans[N];
double dis_out, dis_ans;
int main(int argc, char **argv) {
    registerTestlibCmd(argc, argv);
    n = inf.readInt();
    for (int i = 1; i <= n; i++) {
        a[i].x = inf.readReal();
        a[i].y = inf.readReal();
    }
    for (int i = 1; i <= n; i++) {
        out[i] = ouf.readInt();
        if (out[i] < 1 || out[i] > n) {
            quitf(_wa, "Point %d violates the range[1, %d]", out[i], n);
            return 0;
        }
    }
    for (int i = 1; i <= n; i++) {
        ans_out[i] = ans.readInt();
    }
    if (ans_out[1] != out[1]) {
        quitf(_wa, "The first point of your answer is wrong: expected = %d, found = %d", ans_out[1], out[1]);
        return 0;
    }
    vis_out[out[1]] = vis_ans[ans_out[1]] = 1;
    for (int i = 2; i <= n; i++) {
        if (vis_out[out[i]]) {
            quitf(_wa, "A point appears twice in your answer.");
            return 0;
        } else if (vis_ans[ans_out[i]]) {
            assert(0);
        }
        dis_out += dist(out[i - 1], out[i]);
        dis_ans += dist(ans_out[i - 1], ans_out[i]);
        vis_out[out[i]] = vis_ans[ans_out[i]] = 1;
    }
    if (fabsl(dis_out - dis_ans) <= 1e-10 || fabsl(dis_out - dis_ans) / dis_ans <= 1e-10) {
        quitf(_ok, "Your answer is correct.");
    } else {
        quitf(_wa, "Your answer is wrong: expected = %Lf, found = %Lf", dis_ans, dis_out);
    }
    return 0;
}

回复

11 条回复,欢迎继续交流。

正在加载回复...