Cod sursa(job #593173)

Utilizator SpiderManSimoiu Robert SpiderMan Data 1 iunie 2011 17:16:39
Problema Rays Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.1 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 ;

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 sol = 1 ;

    std :: sort (V + 1, V + (int) V[0].x + 1) ;
    double min = V[1].x ;
    for (int i = 2; i <= V[0].x; ++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) ;
        (x < 0 ? (A[ (int) ++A[0].x ].x = X, A[ (int) A[0].x ].y = Y) : (B[ (int) ++B[0].x ].x = X, B[ (int) B[0].x ].y = Y)) ;
    }
    fprintf (fopen (FOU, "w"), "%d", solve (A) + solve (B)) ;
}