/ SeriousOJ /

Record Detail

Wrong Answer


  
# Status Time Cost Memory Cost
#1 Accepted 0ms 520.0 KiB
#2 Accepted 0ms 512.0 KiB
#3 Accepted 0ms 332.0 KiB
#4 Accepted 0ms 512.0 KiB
#5 Accepted 0ms 284.0 KiB
#6 Accepted 0ms 364.0 KiB
#7 Accepted 0ms 356.0 KiB
#8 Accepted 0ms 540.0 KiB
#9 Accepted 0ms 356.0 KiB
#10 Accepted 0ms 332.0 KiB
#11 Accepted 0ms 560.0 KiB
#12 Accepted 1ms 348.0 KiB
#13 Accepted 0ms 284.0 KiB
#14 Accepted 0ms 328.0 KiB
#15 Accepted 0ms 516.0 KiB
#16 Accepted 0ms 512.0 KiB
#17 Accepted 1ms 436.0 KiB
#18 Accepted 1ms 540.0 KiB
#19 Accepted 0ms 540.0 KiB
#20 Accepted 0ms 284.0 KiB
#21 Wrong Answer 1ms 436.0 KiB
#22 Accepted 1ms 284.0 KiB
#23 Accepted 1ms 540.0 KiB
#24 Wrong Answer 1ms 284.0 KiB

Code

#include <stdio.h>

struct Point {
    int x, y;
};

int isInside(struct Point polygon[], int n, struct Point p) {
    int count = 0, i, next;
    for (i = 0; i < n; i++) {
        next = (i + 1) % n;
        if (p.y > polygon[i].y && p.y <= polygon[next].y || p.y > polygon[next].y && p.y <= polygon[i].y) {
            if (p.x <= (polygon[next].x - polygon[i].x) * (p.y - polygon[i].y) / (polygon[next].y - polygon[i].y) + polygon[i].x)
                count++;
        }
    }
    return count % 2;
}

int main() {
    int n, i;
    struct Point polygon[1000], p;

    scanf("%d", &n);
    for (i = 0; i < n; i++) {
        scanf("%d %d", &polygon[i].x, &polygon[i].y);
    }
    scanf("%d %d", &p.x, &p.y);

    if (isInside(polygon, n, p))
        printf("YES\n");
    else
        printf("NO\n");

    return 0;
}

Information

Submit By
Type
Submission
Problem
P1145 Nobita's Love for Shizuka
Contest
LU IUJPC : Sylhet Division 2024 Replay Contest
Language
C11 (GCC 13.2.0)
Submit At
2024-12-10 11:41:39
Judged At
2024-12-10 11:41:39
Judged By
Score
82
Total Time
1ms
Peak Memory
560.0 KiB