Source Code
#include <bits/stdc++.h>
 
using namespace std;
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
const int N = 1e6+10;
const int mod = 1e9+7;
#define all(x) (x).begin(), (x).end()

//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
struct point_2d{
    ld x , y ;
    point_2d operator- ( point_2d p ){ return { p.x - x , p.y - y }; }    
};
struct circle{
    point_2d O ;
    ld R ;
};
//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
vector<circle> circles;
vector<int> group_number;
//Functions:-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
int find_group( int x ){
    if( x != group_number[x] )x = find_group( group_number[x] );
    return x ;
}
ld sqdis( point_2d d ){
    return ( d.x * d.x + d.y * d.y );
}
bool Can_connect( int x , int y ){
    return ( sqdis( circles[x].O - circles[y].O ) <= ( circles[x].R + circles[y].R ) * ( circles[x].R + circles[y].R ) );
}
ld to_degree( ld rad ){
    return rad * (180.0 / acos(-1));
}

ld find_angle( point_2d a ){
    if( a.x == 0 && a.y == 0 ) 
        while(true);
    if( a.x > 0.0 && a.y == 0.0 ) return 0.00;
    if( a.x == 0.0 && a.y > 0.0 ) return 90.00;
    if( a.x < 0.0 && a.y == 0.0 ) return 180.0;
    if( a.x == 0.0 && a.y < 0.0 ) return 270.0;
    ld angle = atan( abs(a.y) / abs(a.x) );
    angle = to_degree( angle );
    if( a.x > 0.0 && a.y > 0.0 ) return angle ;
    if( a.x < 0.0 && a.y > 0.0 ) return 180.0 - angle ;
    if( a.x < 0.0 && a.y < 0.0 ) return 180.0 + angle ;
    if( a.x > 0.0 && a.y < 0.0 ) return 360.0 - angle ;
}
void find_groups(){

    for( int i = 0 ; i < circles.size() ; i++ )
        for( int j = i+1 ; j < circles.size() ; j++ )
            if( Can_connect( i , j ) )
                group_number[ find_group(j) ] = find_group(i);
    for( int i = 0 ; i < circles.size() ; i++ )
        group_number[i] = find_group( i ) ;
}

vector< pair<ld,ld> > range_and( vector< pair<ld,ld> > a , pair<ld,ld> b ){
    vector< pair<ld,ld> > ans ;
    for( auto i : a ){
        pair<ld,ld> c = { max( i.first , b.first ) , min( i.second , b.second ) };
        if( c.second > c.first )
            ans.push_back(c);
    }
    return ans;
}
vector< pair<ld,ld> > range_or( vector< pair<ld,ld> > a , vector< pair<ld,ld> > b ){
    vector< pair<ld,ld> > ans = b ;
    for( auto i : a )
        ans.push_back(i);
    return ans;
}
string solve(){
    
    int n , r , k ; cin >> n >> r >> k ;
    
    circles.clear();
    circles.resize(n);
    group_number.clear();
    group_number.resize( n );
    
    for( int i = 0 ; i < n ; i++ ){
        cin >> circles[i].O.x >> circles[i].O.y >> circles[i].R ;
        group_number[i] = i ;
    }
    
    find_groups();
    
    map< int , bool > used ;
    map< int , pair<ld,ld> > range ;
    set< int > groups ;

    for( int i = 0 ; i < n ; i++ ){
        groups.insert( group_number[i] ) ;

        ld angle = find_angle( circles[i].O ) ;
        ld theta = to_degree(asin(circles[i].R / sqrt(sqdis( circles[i].O )) )) ;
        ld st_angle = angle - theta + 1e-11 ;
        ld en_angle = angle + theta + 1e-11 ;

        if( st_angle > en_angle )
            en_angle += 360.0;

        if( used[group_number[i]] == false ){
            used[group_number[i]] = true ;
            range[group_number[i]] = { st_angle , en_angle } ;
        }
        range[group_number[i]] = { min( st_angle , range[group_number[i]].first ) , max( en_angle , range[group_number[i]].second ) } ;
    }

    // for( auto i : groups )
    //     cout << range[i].first << " " << range[i].second << " " << range[i].second - range[i].first << endl;
    
    string ans = "";

    for( int c = 1 ; c <= k ; c++ ){
    
        ld l = to_degree( 2 * acos(-1) / c ) ;
        vector< pair< ld , ld > > ans_range ;
        ans_range.push_back( { 0 , l } );

        for( auto i : groups ){
    
            ld w = range[i].second - range[i].first ;
    
            if( w < l ) continue ;
            else if ( 2 * l <= w ) ans_range.clear() ;

            ll val = range[i].first / l ;
            ld st_angle = range[i].first ;
            while( st_angle >= l )
                st_angle -= l ;
            
            ld lp = -st_angle ;
            ld up = ( 2 * l - w ) - st_angle ;

            if( (lp < 0) && (up < 0 ))ans_range = range_and( ans_range , { lp + l , up + l } );
            else if( (lp > 0) && (up > 0 ))ans_range = range_and( ans_range , { lp , up } );
            else{
                vector< pair< ld , ld > > ans1 = range_and( ans_range , { 0 , up} );
                vector< pair< ld , ld > > ans2 = range_and( ans_range , { lp + l , l} );
                ans_range = range_or( ans1 , ans2 ) ;                
            }

        }
        // cout << ans_range.size() << endl;
        if( ans_range.size() )ans += '1';
        else ans += '0';
        // exit(0);
        // if( ans_range.second < ans_range.first )
        //     flag = false;
        // if( flag ) ans += '1';
        // else ans += '0';
    }

    return ans;

}
//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
int main(){
ios::sync_with_stdio(false);
cin.tie(0);
cout.precision(10);
cout << fixed;

// #ifndef ONLINE_JUDGE
// freopen("input.txt" , "r" , stdin );
// #endif
    int t ; cin >> t ;
    while( t-- ) cout << solve() << endl;
}
Copy
Cutting Swiss Cheese zslyer
GNU G++17
7 ms
472 KB
Wrong Answer