Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /***
- Patrick Sava
- Spiru Haret National College of Bucharest
- ***/
- #include <bits/stdc++.h>
- using namespace std;
- # define pb push_back
- # define mp make_pair
- # define FORN( a , b , c ) for ( int a = b ; a <= c ; ++ a )
- # define FORNBACK( a , b , c ) for ( int a = b ; a >= c ; -- a )
- const int MAX = 114 ;
- vector < int > gr [ MAX ] ;
- bitset < MAX > viz ;
- int leftboss [ MAX ] ;
- int rightboss [ MAX ] ;
- int noduri ;
- int v [ MAX ] ;
- int x [ MAX ] ;
- int y [ MAX ] ;
- int relatie ( int i , int xx , int yy , int rz )
- {
- return ( x [ i ] - xx ) * ( x [ i ] - xx ) + ( y [ i ] - yy ) * ( y [ i ] - yy ) <= rz ;
- }
- int euclid ( int i , int j )
- {
- return ( x [ i ] - x [ j ] ) * ( x [ i ] - x [ j ] ) + ( y [ i ] - y [ j ] ) * ( y [ i ] - y [ j ] );
- }
- int black [ MAX ] , b ;
- int white [ MAX ] , w ;
- inline int cuplaj ( int nod )
- {
- if ( viz [ nod ] ) return 0 ;
- viz [ nod ] = 1 ;
- for ( auto x : gr [ nod ] )
- if ( rightboss [ x ] == 0 ){
- leftboss [ nod ] = x ;
- rightboss [ x ] = nod ;
- return 1 ;
- }
- for ( auto x : gr [ nod ] )
- if ( cuplaj ( rightboss [ x ] ) )
- {
- leftboss [ nod ] = x ;
- rightboss [ x ] = nod ;
- return 1 ;
- }
- return 0 ;
- }
- vector < int > best ;
- vector < int > local ;
- bitset < MAX > muie ;
- vector < int > inv [ MAX ] ;
- int determinant ( int a , int b , int c , int d , int e , int f )
- {
- return a * d + c * f + e * b - d * e - a * f - c * b ;
- }
- int main()
- {
- ios :: sync_with_stdio ( false ) ;
- //freopen( "input" , "r" , stdin ) ;
- //freopen( "output" , "w" , stdout ) ;
- int n ;
- cin >> n ;
- int d ;
- cin >> d ;
- FORN ( i , 1 , n )
- cin >> x [ i ] >> y [ i ] ;
- best.pb ( 1 ) ;
- int CET = 1 ;
- /**FORN ( i , 1 , n )
- FORN ( j , 1 , n )
- if ( i != 27 and j != 27 and relatie ( 27 , x [ i ] , y [ i ] , euclid ( i , j ) ) and relatie ( 27 , x [ j ] , y [ j ] , euclid ( i , j ) ) )
- cout << i << ' ' << j << '\n' ;
- return 0 ;**/
- FORN ( A , 1 , n ){
- FORN ( B , A + 1 , n ){
- if ( euclid ( A , B ) > d * d ) continue ;
- local.clear() ;
- int centruAX = x [ B ] ;
- int centruBX = x [ A ] ;
- int centruAY = y [ B ] ;
- int centruBY = y [ A ] ;
- int raza = euclid ( A , B ) ;
- noduri = 0 ;
- FORN ( i , 1 , n ){
- muie [ i ] = 1 ;
- if ( relatie ( i , centruAX , centruAY , raza ) and ( relatie ( i , centruBX , centruBY , raza ) ) ){
- if ( euclid ( i , A ) <= d * d and euclid ( i , B ) <= d * d ){
- ++ noduri ;
- v [ noduri ] = i ;
- muie [ i ] = 0 ;
- }
- }
- }
- muie [ A ] = muie [ B ] = 1 ;
- local.push_back ( A ) ;
- local.push_back ( B ) ;
- w = 0 ;
- b = 0 ;
- FORN ( i , 1 , noduri ){
- if ( determinant( centruAX , centruAY , centruBX , centruBY , x [ v [ i ] ] , y [ v [ i ] ] ) < 0 ){
- ++ w ;
- white [ w ] = v [ i ] ;
- }
- else {
- ++ b ;
- black [ b ] = v [ i ] ;
- }
- }
- /*FORN ( i , 1 , w )
- FORN ( j , 1 , w )
- assert ( euclid ( white [ i ] , white [ j ] ) <= d * d ) ;
- FORN ( i , 1 , b )
- FORN ( j , 1 , b )
- assert ( euclid ( black [ i ] , black [ j ] ) <= d * d ) ;
- */
- FORN ( i , 1 , w ) gr [ i ].clear ( ) ;
- FORN ( i , 1 , b ) inv [ i ].clear ( ) ;
- /*int afis = 0 ;
- if ( A == 14 and B == 63 ) afis = 1 ;
- if ( afis ) {
- cout << "white : " ;
- FORN ( i , 1 , w ) cout << white [ i ] << ' ' ;
- cout << endl ;
- cout << "black : " ;
- FORN ( i , 1 , b ) cout << black [ i ] << ' ' ;
- cout << '\n' ;
- }*/
- //if ( afis ) cout << "SALVATE DIN START : " ;
- FORN ( i , 1 , w )
- {
- //int ok = 1 ;
- FORN ( j , 1 , b ){
- if ( euclid( white [ i ] , black [ j ] ) > d * d ){
- gr [ i ].pb ( j ) ;
- inv [ j ].pb ( i ) ;
- //ok = 0 ;
- }
- }
- //if ( ok and white [ i ] != A and white [ i ] != B ) {
- // local.pb ( white [ i ] ) ;
- // muie [ white [ i ] ] = 1 ;
- //if ( afis )
- //cout << white [ i ] << ' ' ;
- // }
- }
- /* FORN ( i , 1 , b )
- {
- int ok = 1 ;
- FORN ( j , 1 , w ){
- if ( euclid( black [ i ] , white [ j ] ) > d * d ){
- //gr [ i ].pb ( j ) ;
- ok = 0 ;
- }
- }
- if ( ok and black [ i ] != A and black [ i ] != B ) {
- local.pb ( black [ i ] ) ;
- muie [ black [ i ] ] = 1 ;
- //if ( afis )
- //cout << black [ i ] << ' ' ;
- }
- }*/
- /*if ( afis ) cout << endl ;
- FORN ( i , 1 , w )
- {
- for ( auto x : gr [ i ] ){
- assert ( euclid ( white [ i ] , black [ x ] ) > d * d ) ;
- if ( afis )
- cout << "am tras de la " << white [ i ] << " la " << black [ x ] << '\n' ;
- }
- }*/
- //if ( afis ) cout << endl << endl << endl ;
- FORN ( i , 1 , w ) leftboss [ i ] = 0 ;
- FORN ( i , 1 , b ) rightboss [ i ] = 0 ;
- int ok ;
- do {
- ok = 0 ;
- FORN ( i , 1 , w ) viz [ i ] = 0 ;
- FORN ( i , 1 , w )
- if ( leftboss [ i ] == 0 ){
- if ( cuplaj ( i ) )
- ok = 1 ;
- }
- }while ( ok ) ;
- FORN ( i , 1 , w )
- if ( leftboss [ i ] == 0 )
- {
- local.pb ( white [ i ] ) ;
- muie [ white [ i ] ] = 1 ;
- for ( auto x : gr [ i ] )
- muie [ black [ x ] ] = 1 ;
- }
- FORN ( i , 1 , b )
- {
- if ( muie [ black [ i ] ] ) continue ;
- local.pb ( black [ i ] ) ;
- muie [ black [ i ] ] = 1 ;
- for ( auto x : inv [ i ] ){
- muie [ white [ x ] ] = 1 ;
- }
- }
- FORN ( i , 1 , w )
- if ( leftboss [ i ] ){
- if ( muie [ black [ leftboss [ i ] ] ] )
- {
- if ( muie [ white [ i ] ] ) continue ;
- local.pb ( white [ i ] ) ;
- muie [ white [ i ] ] = 1 ;
- }
- else {
- muie [ black [ leftboss [ i ] ] ] = 1 ;
- local.pb ( black [ leftboss [ i ] ] ) ;
- }
- }
- FORN ( i , 1 , n )
- if ( muie [ i ] == 0 )
- local.pb ( i ) ;
- /* if ( afis ){
- cout << local.size ( ) << endl ;
- for ( auto x : local )
- cout << x << ' ' ;
- cout << endl ;
- }*/
- if ( CET < ( int ) local.size() ){
- CET = ( int )local.size() ;
- best = local ;
- }
- }
- }
- for ( auto x : best )
- for ( auto y : best )
- assert ( euclid( x , y ) <= d * d ) ;
- sort ( best.begin() , best.end() ) ;
- cout << CET << '\n' ;
- for ( auto x : best )
- cout << x << ' ' ;
- return 0 ;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement