Advertisement
Guest User

Untitled

a guest
Dec 1st, 2015
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 8.27 KB | None | 0 0
  1. /***
  2.     Patrick Sava
  3.     Spiru Haret National College of Bucharest
  4. ***/
  5.  
  6. #include <bits/stdc++.h>
  7.  
  8. using namespace std;
  9.  
  10. # define pb push_back
  11. # define mp make_pair
  12. # define FORN( a , b , c ) for ( int a = b ; a <= c ; ++ a )
  13. # define FORNBACK( a , b , c ) for ( int a = b ; a >= c ; -- a )
  14. const int MAX = 114 ;
  15. vector < int > gr [ MAX ] ;
  16. bitset < MAX > viz ;
  17. int leftboss [ MAX ] ;
  18. int rightboss [ MAX ] ;
  19. int noduri ;
  20. int v [ MAX ] ;
  21. int x [ MAX ] ;
  22. int y [ MAX ] ;
  23. int relatie ( int i , int xx , int yy , int rz )
  24. {
  25.     return ( x [ i ] - xx ) * ( x [ i ] - xx ) + ( y [ i ] - yy ) * ( y [ i ] - yy ) <= rz ;
  26. }
  27. int euclid ( int i , int j )
  28. {
  29.     return ( x [ i ] - x [ j ] ) * ( x [ i ] - x [ j ] ) + ( y [ i ] - y [ j ] ) * ( y [ i ] - y [ j ] );
  30. }
  31. int black [ MAX ] , b ;
  32. int white [ MAX ] , w ;
  33. inline int cuplaj ( int nod )
  34. {
  35.     if ( viz [ nod ] ) return 0 ;
  36.     viz [ nod ] = 1 ;
  37.     for ( auto x : gr [ nod ] )
  38.         if ( rightboss [ x ] == 0 ){
  39.             leftboss [ nod ] = x ;
  40.             rightboss [ x ] = nod ;
  41.             return 1 ;
  42.         }
  43.     for ( auto x : gr [ nod ] )
  44.         if ( cuplaj ( rightboss [ x ] ) )
  45.         {
  46.             leftboss [ nod ] = x ;
  47.             rightboss [ x ] = nod ;
  48.             return 1 ;
  49.         }
  50.     return 0 ;
  51. }
  52.  
  53. vector < int > best ;
  54. vector < int > local ;
  55. bitset < MAX > muie ;
  56. vector < int > inv [ MAX ] ;
  57. int determinant ( int a , int b , int c , int d , int e , int f )
  58. {
  59.     return a * d + c * f + e * b - d * e - a * f - c * b ;
  60. }
  61.  
  62. int main()
  63. {
  64.     ios :: sync_with_stdio ( false ) ;
  65.  
  66.     //freopen( "input" , "r" , stdin ) ;
  67.     //freopen( "output" , "w" , stdout ) ;
  68.     int n ;
  69.     cin >> n ;
  70.     int d ;
  71.     cin >> d ;
  72.     FORN ( i , 1 , n )
  73.         cin >> x [ i ] >> y [ i ] ;
  74.     best.pb ( 1 ) ;
  75.     int CET = 1 ;
  76.     /**FORN ( i , 1 , n )
  77.         FORN ( j , 1 , n )
  78.             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 ) ) )
  79.                 cout << i << ' ' << j << '\n' ;
  80.     return 0 ;**/
  81.     FORN ( A , 1 , n ){
  82.         FORN ( B , A + 1 , n ){
  83.             if ( euclid ( A , B ) > d * d ) continue ;
  84.             local.clear() ;
  85.             int centruAX = x [ B ] ;
  86.             int centruBX = x [ A ] ;
  87.             int centruAY = y [ B ] ;
  88.             int centruBY = y [ A ] ;
  89.             int raza = euclid ( A , B ) ;
  90.             noduri = 0 ;
  91.             FORN ( i , 1 , n ){
  92.                 muie [ i ] = 1 ;
  93.                 if ( relatie ( i , centruAX , centruAY , raza ) and ( relatie ( i , centruBX , centruBY , raza ) ) ){
  94.                         if ( euclid ( i , A ) <= d * d and euclid ( i , B ) <= d * d ){
  95.                             ++ noduri ;
  96.                             v [ noduri ] = i ;
  97.                             muie [ i ] = 0 ;
  98.                         }
  99.                     }
  100.                 }
  101.             muie [ A ] = muie [ B ] = 1 ;
  102.             local.push_back ( A ) ;
  103.             local.push_back ( B ) ;
  104.             w = 0 ;
  105.             b = 0 ;
  106.             FORN ( i , 1 , noduri ){
  107.                 if ( determinant( centruAX , centruAY , centruBX , centruBY , x [ v [ i ] ] , y [ v [ i ] ] ) < 0 ){
  108.                     ++ w ;
  109.                     white [ w ] = v [ i ] ;
  110.                 }
  111.                 else {
  112.                     ++ b ;
  113.                     black [ b ] = v [ i ] ;
  114.                 }
  115.             }
  116.             /*FORN ( i , 1 , w )
  117.                 FORN ( j , 1 , w )
  118.                     assert ( euclid ( white [ i ] , white [ j ] ) <= d * d ) ;
  119.              FORN ( i , 1 , b )
  120.                 FORN ( j , 1 , b )
  121.                     assert ( euclid ( black [ i ] , black [ j ] ) <= d * d ) ;
  122.             */
  123.             FORN ( i , 1 , w ) gr [ i ].clear ( ) ;
  124.             FORN ( i , 1 , b ) inv [ i ].clear ( ) ;
  125.             /*int afis = 0 ;
  126.             if ( A == 14 and B == 63 ) afis = 1 ;
  127.             if ( afis ) {
  128.                 cout << "white : " ;
  129.                 FORN ( i , 1 , w ) cout << white [ i ] << ' ' ;
  130.                 cout << endl ;
  131.                 cout << "black : " ;
  132.                 FORN ( i , 1 , b ) cout << black [ i ] << ' ' ;
  133.  
  134.                 cout << '\n' ;
  135.             }*/
  136.             //if ( afis ) cout << "SALVATE DIN START : " ;
  137.             FORN ( i , 1 , w )
  138.             {
  139.                 //int ok = 1 ;
  140.                 FORN ( j , 1 , b ){
  141.                     if ( euclid( white [ i ] , black [ j ] ) > d * d ){
  142.                         gr [ i ].pb ( j ) ;
  143.                         inv [ j ].pb ( i ) ;
  144.                         //ok = 0 ;
  145.                     }
  146.                 }
  147.                 //if ( ok and white [ i ] != A and white [ i ] != B ) {
  148.                 //    local.pb ( white [ i ] ) ;
  149.                 //    muie [ white [ i ] ] = 1 ;
  150.                     //if ( afis )
  151.                     //cout << white [ i ] << ' ' ;
  152.                // }
  153.             }
  154.            /* FORN ( i , 1 , b )
  155.             {
  156.                 int ok = 1 ;
  157.                 FORN ( j , 1 , w ){
  158.                     if ( euclid( black [ i ] , white [ j ] ) > d * d ){
  159.                         //gr [ i ].pb ( j ) ;
  160.                         ok = 0 ;
  161.                     }
  162.                 }
  163.                 if ( ok and black [ i ] != A and black [ i ] != B ) {
  164.                     local.pb ( black [ i ] ) ;
  165.                     muie [ black [ i ] ] = 1 ;
  166.                     //if ( afis )
  167.                     //cout << black [ i ] << ' ' ;
  168.                 }
  169.             }*/
  170.             /*if ( afis ) cout << endl ;
  171.             FORN ( i , 1 , w )
  172.             {
  173.                 for ( auto x : gr [ i ] ){
  174.                     assert ( euclid ( white [ i ] , black [ x ] ) > d * d ) ;
  175.                     if ( afis )
  176.                     cout << "am tras de la " << white [ i ] << " la " << black [ x ] << '\n' ;
  177.                 }
  178.             }*/
  179.             //if ( afis ) cout << endl << endl << endl ;
  180.             FORN ( i , 1 , w ) leftboss [ i ] = 0 ;
  181.             FORN ( i , 1 , b ) rightboss [ i ] = 0 ;
  182.             int ok ;
  183.             do {
  184.                 ok = 0 ;
  185.                 FORN ( i , 1 , w ) viz [ i ] = 0 ;
  186.                 FORN ( i , 1 , w )
  187.                     if ( leftboss [ i ] == 0 ){
  188.                         if ( cuplaj ( i ) )
  189.                             ok = 1 ;
  190.                     }
  191.             }while ( ok ) ;
  192.             FORN ( i , 1 , w )
  193.                 if ( leftboss [ i ] == 0 )
  194.                 {
  195.                     local.pb ( white [ i ] ) ;
  196.                     muie [ white [ i ] ] = 1 ;
  197.                     for ( auto x : gr [ i ] )
  198.                         muie [ black [ x ] ] = 1 ;
  199.                 }
  200.             FORN ( i , 1 , b )
  201.                 {
  202.                     if ( muie [ black [ i ] ] ) continue ;
  203.                     local.pb ( black [ i ] ) ;
  204.                     muie [ black [ i ] ] = 1 ;
  205.                     for ( auto x : inv [ i ] ){
  206.                         muie [ white [ x ] ] = 1 ;
  207.                     }
  208.                 }
  209.             FORN ( i , 1 , w )
  210.                 if ( leftboss [ i ] ){
  211.                     if ( muie [ black [ leftboss [ i ] ] ] )
  212.                     {
  213.                         if ( muie [ white [ i ] ] ) continue ;
  214.  
  215.                         local.pb ( white [ i ] ) ;
  216.                         muie [ white [ i ] ] = 1 ;
  217.                     }
  218.                     else {
  219.                         muie [ black [ leftboss [ i ] ] ] = 1 ;
  220.                         local.pb ( black [ leftboss [ i ] ] ) ;
  221.                     }
  222.                 }
  223.             FORN ( i , 1 , n )
  224.                 if ( muie [ i ] == 0 )
  225.                     local.pb ( i ) ;
  226.            /* if ( afis ){
  227.                 cout << local.size ( ) << endl ;
  228.                 for ( auto x : local )
  229.                     cout << x << ' ' ;
  230.  
  231.                 cout << endl ;
  232.             }*/
  233.             if ( CET < ( int ) local.size() ){
  234.                 CET = ( int )local.size() ;
  235.                 best = local ;
  236.             }
  237.         }
  238.     }
  239.     for ( auto x : best )
  240.         for ( auto y : best )
  241.             assert ( euclid( x , y ) <= d * d ) ;
  242.     sort ( best.begin() , best.end() ) ;
  243.     cout << CET << '\n' ;
  244.     for ( auto x : best )
  245.         cout << x << ' ' ;
  246.     return 0 ;
  247. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement