Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<bits/stdc++.h>
- #define pb(x) push_back(x)
- #define N 235
- #define Vector Point
- #define INF (1<<20)
- using namespace std;
- struct Point{
- long long x, y;
- int id;
- Point(long long _x, long long _y, int _id){x = _x; y = _y; id = _id; }
- Point(){}
- void read(){ scanf("%I64d%I64d", &x, &y); }
- };
- bool operator <(const Point &p1, const Point &p2){
- if(p1.x != p2.x)return p1.x < p2.x;
- return p1.y < p2.y;
- }
- Point operator -(const Point &A, const Point &B){ return Point(A.x - B.x, A.y - B.y, 0); }
- long long cross(const Vector &A, const Vector &B){ return A.x * B.y - A.y * B.x; }
- int UP[N][N], DOWN[N][N];
- Point P[N];
- bool memo[N][N][N];
- int res[N], PD[N][N][N];
- int main(){
- freopen( "division.in" , "r" , stdin );
- freopen( "division.out" , "w" , stdout );
- int n;
- while(cin>>n){
- for(int i = 1; i <= n; i++)P[i].read(), P[i].id = i;
- sort(P + 1, P + n + 1);
- int aux;
- for(int i = 1; i <= n; i++){
- P[0] = P[i];
- P[0].x -= INF;
- for(int l = 1; l <= n; l++){
- if(P[l].x >= P[i].x)continue;
- aux = cross(P[i] - P[0], P[l] - P[0]);
- if(aux > 0)UP[0][i]++;
- else if(aux < 0)DOWN[0][i]++;
- }
- }
- for(int i = 1; i <= n; i++){
- P[n + 1] = P[i];
- P[n + 1].x += INF;
- P[n + 1].id = n + 1;
- for(int j = i + 1; j <= n + 1; j++){
- if(P[i].x == P[j].x)continue;
- for(int l = 1; l <= n; l++){
- if(P[l].x < P[i].x || P[l].x >= P[j].x)continue;
- aux = cross(P[j] - P[i], P[l] - P[i]);
- if(aux > 0)UP[i][j]++;
- else if(aux < 0)DOWN[i][j]++;
- }
- }
- }
- memset(PD, -1, sizeof PD);
- int cu, cd;
- for(int i = 1; i <= n; i++){
- cd = DOWN[i][n + 1];
- cu = UP[i][n + 1];
- memo[i][cd][cu] = true;
- PD[i][cd][cu] = -1;
- }
- for(int i = n; i >= 1; i--){
- for(int u = 0; u <= n; u++){
- for(int d = 0; u + d <= n; d++){
- if(memo[i][d][u])continue;
- for(int j = i + 1; j <= n; j++){
- if(P[i].x == P[j].x)continue;
- cd = DOWN[i][j];
- cu = UP[i][j];
- if(u < cu || d < cd)continue;
- memo[i][d][u] = memo[j][d - cd][u - cu];
- PD[i][d][u] = j;
- if(memo[i][d][u])break;
- }
- }
- }
- }
- for(int u = 0; u <= n; u++){
- for(int d = 0; u + d <= n; d++){
- for(int i = 1; i <= n; i++){
- cd = DOWN[0][i];
- cu = UP[0][i];
- if(u < cu || d < cd)continue;
- if(memo[i][d - cd][u - cu]){
- memo[0][d][u] = true;
- PD[0][d][u] = i;
- }
- if(memo[0][d][u])break;
- }
- }
- }
- int ans = (1<<30), mini, maxi;
- int ru, rd;
- for(int u = 0; u <= n; u++){
- for(int d = 0, s; d + u <= n; d++){
- if(!memo[0][d][u])continue;
- s = n - u - d;
- maxi = mini = s;
- maxi = max(maxi, max(d, u));
- mini = min(mini, min(d, u));
- if(maxi - mini < ans){
- ans = maxi - mini;
- rd = d;
- ru = u;
- }
- }
- }
- int cur = 0, to, top = 0;
- while(PD[cur][rd][ru] != -1){
- to = PD[cur][rd][ru];
- rd -= DOWN[cur][to];
- ru -= UP[cur][to];
- cur = to;
- if(to != -1)res[top++] = to;
- }
- printf("%d\n", top);
- for(int i = 0; i < top; i++){
- if(i)printf(" ");
- printf("%d", P[res[i]].id);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement