Cod sursa(job #593174)

Utilizator SpiderManSimoiu Robert SpiderMan Data 1 iunie 2011 17:20:28
Problema Rays Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.11 kb
# include <algorithm>
# include <cstdio>
# include <cmath>

const char *FIN = "rays.in", *FOU = "rays.out" ;
const int MAX = 200005 ;

struct vector {
    double x, y ;
} ;

vector A[MAX], B[MAX] ;
int N, A1, B1 ;

bool operator < ( const vector& lhs , const vector& rhs ) {
    if ( lhs.x == rhs.x )
        return lhs.y < rhs.y;

    return lhs.x < rhs.y;
}

int solve (vector *V, int N) {
    int sol = 1 ;

    std :: sort (V, V + N) ;
    double min = V[0].x ;
    for (int i = 1; i < N; ++i) {
        if (min < V[i].y) {
            min = V[i].x, ++sol ;
        }
    }
    return sol ;
}


int main (void) {
    freopen (FIN, "r", stdin) ;

    scanf ("%d", &N) ;
    for (int i = 1, x, y1, y2; i <= N; ++i) {
        scanf ("%d %d %d", &x, &y1, &y2) ;
        double X = atan2 (y1, abs (x)), Y = atan2 (y2, abs (x)) ;
        if (X < Y) std :: swap (X, Y) ;
        if (x < 0) {
            A[ A1 ].x = X, A[ A1++ ].y = Y ;
        } else {
            B[ B1 ].x = X, B[ B1++ ].y = Y ;
        }
    }
    fprintf (fopen (FOU, "w"), "%d", solve (A, A1) + solve (B, B1)) ;
}