Cod sursa(job #2226761)

Utilizator Bodo171Bogdan Pop Bodo171 Data 30 iulie 2018 16:30:05
Problema Poligon Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.07 kb
#include <bits/stdc++.h>
#define MAXN 800

struct Point{ int x, y;} v[1 + MAXN];
inline long long S(Point A, Point B, Point C){
    return (long long)(1LL * A.x * B.y + 1LL * A.y * C.x + 1LL * B.x * C.y) -
           (long long)(1LL * A.x * C.y + 1LL * A.y * B.x + 1LL * C.x * B.y);
}
inline int sgn(long long a){
    if(a == 0) return 0;
    if(a > 0) return 1;
    return -1;
}

int main(){
    FILE*fi,*fo;
    fi = fopen("poligon.in","r");
    fo = fopen("poligon.out","w");

    int n, m;
    fscanf(fi,"%d%d", &n, &m);
    for(int i = 1; i <= n; i++)
        fscanf(fi,"%d%d", &v[i].x, &v[i].y);
    for(int i = 1; i <= n; i++)
        for(int j = i + 1; j <= n; j++){
            Point A = v[i], B = v[i % n + 1];
            Point C = v[j], D = v[j % n + 1];
            if(A.y == B.y || C.y == D.y) continue;
            if(sgn(S(A, B, C)) != sgn(S(A, B, D)) &&
               sgn(S(A, B, C)) * sgn(S(A, B, D)) &&
               sgn(S(C, D, A)) != sgn(S(C, D, B)) &&
               sgn(S(C, D, A)) * sgn(S(C, D, B))) assert(0);
        }

    return 0;
}