编号 题目 状态 分数 总时间 内存 代码 / 答案文件 提交者 提交时间
#2313 #1003. 凸多边形 Compile Error 0 0 ms 0 K C / 1.4 K t330026238 2023-11-17 10:36:34
显示原始代码
#include <stdio.h>
#include <math.h>
#define M_PI 3.14

typedef struct {
    double x;
    double y;
} Point;

double vector_magnitude(Point u) { return sqrt(u.x * u.x + u.y * u.y); }

double vector_dot_product(Point u, Point v) { return u.x * v.x + u.y * v.y; }

double vector_angle(Point u, Point v) {
    double dot_product = vector_dot_product(u, v);
    double magnitude_u = vector_magnitude(u);
    double magnitude_v = vector_magnitude(v);

    double angle = acos(dot_product / (magnitude_u * magnitude_v));
    return angle;
}

int is_convex_quadrilateral(Point A, Point B, Point C, Point D) {
    Point AB = { B.x - A.x, B.y - A.y };
    Point BC = { C.x - B.x, C.y - B.y };
    Point CD = { D.x - C.x, D.y - C.y };
    Point DA = { A.x - D.x, A.y - D.y };

    double angles[4] = { vector_angle(AB, BC), vector_angle(BC, CD), vector_angle(CD, DA),
                         vector_angle(DA, AB) };

    for (int i = 0; i < 4; i++) {
        if (angles[i] >= M_PI) {
            return 0;
        }
    }

    return 1;
}

int main() {
    Point A, B, C, D;

    scanf_s("%lf%lf", &A.x, &A.y);
    scanf_s("%lf%lf", &B.x, &B.y);
    scanf_s("%lf%lf", &C.x, &C.y);
    scanf_s("%lf%lf", &D.x, &D.y);

    int result = is_convex_quadrilateral(A, B, C, D);

    if (result == 1) {
        printf("yes\n");
    } else {
        printf("no\n");
    }

    return 0;
}

编译信息

/sandbox/1/a.c:3:9: warning: 'M_PI' macro redefined [-Wmacro-redefined]
#define M_PI 3.14
        ^
/usr/include/math.h:1070:10: note: previous definition is here
# define M_PI           3.14159265358979323846  /* pi */
         ^
/sandbox/1/a.c:52:5: warning: implicit declaration of function 'scanf_s' is invalid in C99 [-Wimplicit-function-declaration]
    scanf_s("%lf%lf", &A.x, &A.y);
    ^
2 warnings generated.
/usr/bin/ld: /tmp/a-eaaccb.o: in function `main':
a.c:(.text+0x563): undefined reference to `scanf_s'
/usr/bin/ld: a.c:(.text+0x577): undefined reference to `scanf_s'
/usr/bin/ld: a.c:(.text+0x58b): undefined reference to `scanf_s'
/usr/bin/ld: a.c:(.text+0x59f): undefined reference to `scanf_s'
clang: error: linker command failed with exit code 1 (use -v to see invocation)