Advertisement
BoxerTC

Untitled

Jun 27th, 2015
254
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 4.83 KB | None | 0 0
  1. #include<bits/stdc++.h>
  2. #define pb(x) push_back(x)
  3. #define N 235
  4.  
  5. #define Vector Point
  6. #define INF (1<<20)
  7.  
  8. using namespace std;
  9.  
  10. struct Point{
  11.    
  12.     long long x, y;
  13.     int id;
  14.    
  15.     Point(long long _x, long long _y, int _id){x = _x; y = _y; id = _id; }
  16.     Point(){}  
  17.     void read(){ scanf("%I64d%I64d", &x, &y); }
  18. };
  19.  
  20. bool operator <(const Point &p1, const Point &p2){
  21.    
  22.     if(p1.x != p2.x)return p1.x < p2.x;
  23.     return p1.y < p2.y;
  24. }
  25.  
  26. Point operator -(const Point &A, const Point &B){ return Point(A.x - B.x, A.y - B.y, 0); }
  27. long long cross(const Vector &A, const Vector &B){ return A.x * B.y - A.y * B.x; }
  28.  
  29. int UP[N][N], DOWN[N][N];
  30. Point P[N];
  31.  
  32. bool memo[N][N][N];
  33. int res[N], PD[N][N][N];
  34.  
  35. int main(){
  36.     freopen( "division.in" , "r" , stdin );
  37.     freopen( "division.out" , "w" , stdout );
  38.     int n;
  39.     while(cin>>n){
  40.        
  41.         for(int i = 1; i <= n; i++)P[i].read(), P[i].id = i;
  42.         sort(P + 1, P + n + 1);
  43.        
  44.         int aux;
  45.         for(int i = 1; i <= n; i++){
  46.            
  47.             P[0] = P[i];
  48.             P[0].x -= INF;
  49.  
  50.             for(int l = 1; l <= n; l++){
  51.                    
  52.                 if(P[l].x >= P[i].x)continue;
  53.                 aux = cross(P[i] - P[0], P[l] - P[0]);
  54.                    
  55.                 if(aux > 0)UP[0][i]++;
  56.                 else if(aux < 0)DOWN[0][i]++;
  57.             }
  58.            
  59.         }
  60.         for(int i = 1; i <= n; i++){
  61.            
  62.             P[n + 1] = P[i];
  63.             P[n + 1].x += INF;
  64.             P[n + 1].id = n + 1;
  65.            
  66.             for(int j = i + 1; j <= n + 1; j++){
  67.                
  68.                 if(P[i].x == P[j].x)continue;
  69.                 for(int l = 1; l <= n; l++){
  70.                    
  71.                     if(P[l].x < P[i].x || P[l].x >= P[j].x)continue;
  72.                     aux = cross(P[j] - P[i], P[l] - P[i]);
  73.    
  74.                     if(aux > 0)UP[i][j]++;
  75.                     else if(aux < 0)DOWN[i][j]++;
  76.                 }
  77.             }  
  78.         }
  79.        
  80.         memset(PD, -1, sizeof PD);
  81.         int cu, cd;
  82.        
  83.         for(int i = 1; i <= n; i++){
  84.            
  85.             cd = DOWN[i][n + 1];
  86.             cu = UP[i][n + 1];
  87.            
  88.             memo[i][cd][cu] = true;
  89.             PD[i][cd][cu] = -1;
  90.         }
  91.        
  92.         for(int i = n; i >= 1; i--){
  93.             for(int u = 0; u <= n; u++){
  94.                 for(int d = 0; u + d <= n; d++){
  95.                    
  96.                     if(memo[i][d][u])continue;
  97.                     for(int j = i + 1; j <= n; j++){
  98.                        
  99.                         if(P[i].x == P[j].x)continue;
  100.                        
  101.                         cd = DOWN[i][j];
  102.                         cu = UP[i][j];
  103.                        
  104.                         if(u < cu || d < cd)continue;
  105.                         memo[i][d][u] = memo[j][d - cd][u - cu];
  106.                        
  107.                         PD[i][d][u] = j;
  108.                         if(memo[i][d][u])break;
  109.                     }
  110.                 }                      
  111.             }
  112.         }
  113.        
  114.        
  115.         for(int u = 0; u <= n; u++){
  116.             for(int d = 0; u + d <= n; d++){
  117.                
  118.                 for(int i = 1; i <= n; i++){
  119.                    
  120.                     cd = DOWN[0][i];
  121.                     cu = UP[0][i];
  122.                    
  123.                     if(u < cu || d < cd)continue;
  124.                     if(memo[i][d - cd][u - cu]){
  125.                        
  126.                         memo[0][d][u] = true;
  127.                         PD[0][d][u] = i;
  128.                     }
  129.                     if(memo[0][d][u])break;    
  130.                 }
  131.             }
  132.         }
  133.        
  134.         int ans = (1<<30), mini, maxi;
  135.         int ru, rd;
  136.        
  137.         for(int u = 0; u <= n; u++){
  138.             for(int d = 0, s; d + u <= n; d++){
  139.                
  140.                 if(!memo[0][d][u])continue;
  141.                
  142.                 s = n - u - d;
  143.                 maxi = mini = s;
  144.                
  145.                 maxi = max(maxi, max(d, u));
  146.                 mini = min(mini, min(d, u));
  147.                
  148.                 if(maxi - mini < ans){  
  149.                
  150.                     ans = maxi - mini;
  151.                     rd = d;
  152.                     ru = u;
  153.                 }
  154.             }
  155.         }
  156.        
  157.         int cur = 0, to, top = 0;
  158.         while(PD[cur][rd][ru] != -1){
  159.            
  160.             to = PD[cur][rd][ru];
  161.             rd -= DOWN[cur][to];
  162.            
  163.             ru -= UP[cur][to];
  164.             cur = to;
  165.            
  166.             if(to != -1)res[top++] = to;
  167.         }
  168.        
  169.         printf("%d\n", top);
  170.         for(int i = 0; i < top; i++){
  171.            
  172.             if(i)printf(" ");
  173.             printf("%d", P[res[i]].id);
  174.         }
  175.        
  176.        
  177.     }
  178.    
  179.    
  180. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement