#ifdef __FAST_MATH__ #undef __FAST_MATH__ #endif #include #include #include #include #include #include #include struct region_t { double start; double end; double z; region_t( double const& s=0, double const& e=0, double const& z=0 ) : start(s), end(e), z(z) {} }; bool operator < ( struct region_t const& a, struct region_t const& b ) { if( a.z < b.z ) return true; return false; } region_t project_tree( int x_i, int y_i, int r_i ) { double x = x_i; double y = y_i; double const l = sqrt( x*x + y*y ); double const r = r_i; double const a = asin( r/l ); x /= l; y /= l; double phi = acos( y ); if( asin(x) < 0 ) phi += 2.0*(M_PI-phi); region_t reg( phi-a, phi+a, l-r ); //if( reg.start < 0 ) reg.start += 2.0*M_PI; //if( reg.end < 0 ) reg.end += 2.0*M_PI; return reg; } std::vector regions; void recalculate_visible_areas( void ) { for( std::vector::iterator i = regions.begin(); i != regions.end(); ++i ) for( std::vector::iterator j = i+1; j != regions.end(); ++j ) { if( j->z < i->z ) continue; bool const shift_i = i->start < 0; bool const shift_j = j->start < 0; if( shift_i ) { i->start += 2.0*M_PI; i->end += 2.0*M_PI; } if( shift_j ) { j->start += 2.0*M_PI; j->end += 2.0*M_PI; } if( i->start <= j->start && i->end >= j->end ) /// komplett verdeckt j->z = 0; else if( i->end > j->start && i->end < j->end ) /// 'links' verdeckt j->start = i->end; else if( i->start > j->start && i->start <= j->end ) /// 'rechts' verdeckt j->end = i->start; else /// verdeckt ueberhauptnicht. {} if( shift_i ) { i->start -= 2.0*M_PI; i->end -= 2.0*M_PI; } if( shift_j ) { j->start -= 2.0*M_PI; j->end -= 2.0*M_PI; } } } int main( int argsc __attribute__((unused)), char ** argsv __attribute__((unused)) ) { int i,n; int x,y,r; FILE *input = fopen("forest.in", "rt"); regions.resize(1000); assert( input && "file \'forest.in\' not in working directory" ); while( fscanf( input, "%d", &n ) == 1 ) { if( !n ) break; for( i=0; i