90pts求助,第1个点过不了
查看原帖
90pts求助,第1个点过不了
225072
Astralis楼主2020/5/16 07:36
#include<bits/stdc++.h>
using namespace std;
int Max[4],tot,ans,sum,n,now,whe[50001];
struct dian
{
	int x;
	int y;
	int id;
};
dian a[50001],b[50001],c[50001],d[50001];
bool comp1(dian a,dian b)
{
	return a.y>b.y;
}
bool comp2(dian a,dian b)
{
	return a.y<b.y;
}
bool comp3(dian a,dian b)
{
	return a.x<b.x;
}
bool comp4(dian a,dian b)
{
	return a.x>b.x;
}
void dfs(int q,int w,int e,int r,int left)
{
	ans=min(ans,(a[q].y-b[w].y)*(d[r].x-c[e].x));
    if(left>=1)
    {
        if(whe[a[q].id]==0)
        {     
            whe[a[q].id]=1;
    	    dfs(q+1,w,e,r,left-1);
    	    whe[a[q].id]=0;
    	}
    	else
    	dfs(q+1,w,e,r,left);
        if(whe[b[w].id]==0)
        {     
            whe[b[w].id]=1;
    	    dfs(q,w+1,e,r,left-1);
    	    whe[b[w].id]=0;
    	}
    	else
    	dfs(q,w+1,e,r,left);
        if(whe[c[e].id]==0)
        {     
            whe[c[e].id]=1;
    	    dfs(q,w,e+1,r,left-1);
    	    whe[c[e].id]=0;
    	}
    	else
    	dfs(q,w,e+1,r,left);
        if(whe[d[r].id]==0)
        {     
            whe[d[r].id]=1;
    	    dfs(q,w,e,r+1,left-1);
    	    whe[d[r].id]=0;
    	}
    	else
    	dfs(q,w,e,r+1,left);
    }
    if(left>=2)
    {
        if(whe[a[q].id]==0&&whe[a[q+1].id]==0)
        {     
            whe[a[q].id]=whe[a[q+1].id]=1;
    	    dfs(q+2,w,e,r,left-2);
    	    whe[a[q].id]=whe[a[q+1].id]=0;
    	}
        if(whe[a[q].id]==1&&whe[a[q+1].id]==0)
        {
            whe[a[q+1].id]=1;
    	    dfs(q+2,w,e,r,left-1);
    	    whe[a[q+1].id]=0;
        }
        if(whe[a[q+1].id]==1&&whe[a[q].id]==0)
        {
            whe[a[q].id]=1;
    	    dfs(q+2,w,e,r,left-1);
    	    whe[a[q].id]=0;
        }
        if(whe[a[q].id]==1&&whe[a[q+1].id]==1)
        {
    	    dfs(q+2,w,e,r,left);
        }
        if(whe[b[w].id]==0&&whe[b[w+1].id]==0)
        {     
            whe[b[w].id]=whe[b[w+1].id]=1;
    	    dfs(q,w+2,e,r,left-2);
    	    whe[b[w].id]=whe[b[w+1].id]=0;
    	}
        if(whe[b[w].id]==1&&whe[b[w+1].id]==0)
        {
            whe[b[w+1].id]=1;
    	    dfs(q,w+2,e,r,left-1);
    	    whe[b[w+1].id]=0;
        }
        if(whe[b[w+1].id]==1&&whe[b[w].id]==0)
        {
            whe[b[w].id]=1;
    	    dfs(q,w+2,e,r,left-1);
    	    whe[b[w].id]=0;
        }
        if(whe[b[w].id]==1&&whe[b[w+1].id]==1)
        {
    	    dfs(q,w+2,e,r,left);
        }
        if(whe[c[e].id]==0&&whe[c[e+1].id]==0)
        {     
            whe[c[e].id]=whe[c[e+1].id]=1;
    	    dfs(q,w,e+2,r,left-2);
    	    whe[c[e].id]=whe[c[e+1].id]=0;
    	}
        if(whe[c[e].id]==1&&whe[c[e+1].id]==0)
        {
            whe[c[e+1].id]=1;
    	    dfs(q,w,e+2,r,left-1);
    	    whe[c[e+1].id]=0;
        }
        if(whe[c[e+1].id]==1&&whe[c[e].id]==0)
        {
            whe[c[e].id]=1;
    	    dfs(q,w,e+2,r,left-1);
    	    whe[c[e].id]=0;
        }
        if(whe[c[e].id]==1&&whe[c[e+1].id]==1)
        {
    	    dfs(q,w,e+2,r,left);
        }
        if(whe[d[r].id]==0&&whe[d[r+1].id]==0)
        {     
            whe[d[r].id]=whe[d[r+1].id]=1;
    	    dfs(q,w,e,r+2,left-2);
    	    whe[d[r].id]=whe[d[r+1].id]=0;
    	}
        if(whe[d[r].id]==1&&whe[d[r+1].id]==0)
        {
            whe[d[r+1].id]=1;
    	    dfs(q,w,e,r+2,left-1);
    	    whe[d[r+1].id]=0;
        }
        if(whe[d[r+1].id]==1&&whe[d[r].id]==0)
        {
            whe[d[r].id]=1;
    	    dfs(q,w,e,r+2,left-1);
    	    whe[d[r].id]=0;
        }
        if(whe[d[r].id]==1&&whe[d[r+1].id]==1)
        {
    	    dfs(q,w,e,r+2,left);
        }
    }
    if(left==3)
    {
        if(whe[a[q].id]==1&&whe[a[q+1].id]==1&&whe[a[q+2].id]==1)//1
        {
        	dfs(q+3,w,e,r,left);
        }
        if(whe[a[q].id]==1&&whe[a[q+1].id]==1&&whe[a[q+2].id]==0)//2
        {
        	whe[a[q+2].id]=1;
        	dfs(q+3,w,e,r,left-1);
        	whe[a[q+2].id]=0;
        }
        if(whe[a[q].id]==1&&whe[a[q+1].id]==0&&whe[a[q+2].id]==1)//3
        {
        	whe[a[q+1].id]=1;
        	dfs(q+3,w,e,r,left-1);
        	whe[a[q+1].id]=0;
        }
        if(whe[a[q].id]==1&&whe[a[q+1].id]==0&&whe[a[q+2].id]==0)//4
        {
        	whe[a[q+1].id]=whe[a[q+2].id]=1;
        	dfs(q+3,w,e,r,left-2);
        	whe[a[q+1].id]=whe[a[q+2].id]=0;
        }
        if(whe[a[q].id]==0&&whe[a[q+1].id]==1&&whe[a[q+2].id]==1)//5
        {
        	whe[a[q].id]=1;
        	dfs(q+3,w,e,r,left-1);
        	whe[a[q].id]=0;
        }
        if(whe[a[q].id]==0&&whe[a[q+1].id]==1&&whe[a[q+2].id]==0)//6
        {
        	whe[a[q+2].id]=whe[a[q].id]=1;
        	dfs(q+3,w,e,r,left-2);
        	whe[a[q+2].id]=whe[a[q].id]=0;
        }
        if(whe[a[q].id]==0&&whe[a[q+1].id]==0&&whe[a[q+2].id]==1)//7
        {
        	whe[a[q+1].id]=whe[a[q].id]=1;
        	dfs(q+3,w,e,r,left-2);
        	whe[a[q+1].id]=whe[a[q].id]=0;
        }
        if(whe[a[q].id]==0&&whe[a[q+1].id]==0&&whe[a[q+2].id]==0)//8
        {
        	whe[a[q+1].id]=whe[a[q+2].id]=whe[a[q].id]=1;
        	dfs(q+3,w,e,r,left-3);
        	whe[a[q+1].id]=whe[a[q+2].id]=whe[a[q].id]=0;
        }   
		//
		        if(whe[b[w].id]==1&&whe[b[w+1].id]==1&&whe[b[w+2].id]==1)//1
        {
        	dfs(q,w+3,e,r,left);
        }
        if(whe[b[w].id]==1&&whe[b[w+1].id]==1&&whe[b[w+2].id]==0)//2
        {
        	whe[b[w+2].id]=1;
        	dfs(q,w+3,e,r,left-1);
        	whe[b[w+2].id]=0;
        }
        if(whe[b[w].id]==1&&whe[b[w+1].id]==0&&whe[b[w+2].id]==1)//3
        {
        	whe[b[w+1].id]=1;
        	dfs(q,w+3,e,r,left-1);
        	whe[b[w+1].id]=0;
        }
        if(whe[b[w].id]==1&&whe[b[w+1].id]==0&&whe[b[w+2].id]==0)//4
        {
        	whe[b[w+1].id]=whe[b[w+2].id]=1;
        	dfs(q,w+3,e,r,left-2);
        	whe[b[w+1].id]=whe[b[w+2].id]=0;
        }
        if(whe[b[w].id]==0&&whe[b[w+1].id]==1&&whe[b[w+2].id]==1)//5
        {
        	whe[b[w].id]=1;
        	dfs(q,w+3,e,r,left-1);
        	whe[b[w].id]=0;
        }
        if(whe[b[w].id]==0&&whe[b[w+1].id]==1&&whe[b[w+2].id]==0)//6
        {
        	whe[b[w+2].id]=whe[b[w].id]=1;
        	dfs(q,w+3,e,r,left-2);
        	whe[b[w+2].id]=whe[b[w].id]=0;
        }
        if(whe[b[w].id]==0&&whe[b[w+1].id]==0&&whe[b[w+2].id]==1)//7
        {
        	whe[b[w+1].id]=whe[b[w].id]=1;
        	dfs(q,w+3,e,r,left-2);
        	whe[b[w+1].id]=whe[b[w].id]=0;
        }
        if(whe[b[w].id]==0&&whe[b[w+1].id]==0&&whe[b[w+2].id]==0)//8
        {
        	whe[b[w+1].id]=whe[b[w+2].id]=whe[b[w].id]=1;
        	dfs(q,w+3,e,r,left-3);
        	whe[b[w+1].id]=whe[b[w+2].id]=whe[b[w].id]=0;
        }   
		//
		        if(whe[d[r].id]==1&&whe[d[r+1].id]==1&&whe[d[r+2].id]==1)//1
        {
        	dfs(q,w,e,r+3,left);
        }
        if(whe[d[r].id]==1&&whe[d[r+1].id]==1&&whe[d[r+2].id]==0)//2
        {
        	whe[d[r+2].id]=1;
        	dfs(q,w,e,r+3,left-1);
        	whe[d[r+2].id]=0;
        }
        if(whe[d[r].id]==1&&whe[d[r+1].id]==0&&whe[d[r+2].id]==1)//3
        {
        	whe[d[r+1].id]=1;
        	dfs(q,w,e,r+3,left-1);
        	whe[d[r+1].id]=0;
        }
        if(whe[d[r].id]==1&&whe[d[r+1].id]==0&&whe[d[r+2].id]==0)//4
        {
        	whe[d[r+1].id]=whe[d[r+2].id]=1;
        	dfs(q,w,e,r+3,left-2);
        	whe[d[r+1].id]=whe[d[r+2].id]=0;
        }
        if(whe[d[r].id]==0&&whe[d[r+1].id]==1&&whe[d[r+2].id]==1)//5
        {
        	whe[d[r].id]=1;
        	dfs(q,w,e,r+3,left-1);
        	whe[d[r].id]=0;
        }
        if(whe[d[r].id]==0&&whe[d[r+1].id]==1&&whe[d[r+2].id]==0)//6
        {
        	whe[d[r+2].id]=whe[d[r].id]=1;
        	dfs(q,w,e,r+3,left-2);
        	whe[d[r+2].id]=whe[d[r].id]=0;
        }
        if(whe[d[r].id]==0&&whe[d[r+1].id]==0&&whe[d[r+2].id]==1)//7
        {
        	whe[d[r+1].id]=whe[d[r].id]=1;
        	dfs(q,w,e,r+3,left-2);
        	whe[d[r+1].id]=whe[d[r].id]=0;
        }
        if(whe[d[r].id]==0&&whe[d[r+1].id]==0&&whe[d[r+2].id]==0)//8
        {
        	whe[d[r+1].id]=whe[d[r+2].id]=whe[d[r].id]=1;
        	dfs(q,w,e,r+3,left-3);
        	whe[d[r+1].id]=whe[d[r+2].id]=whe[d[r].id]=0;
        }   
		//
		        if(whe[c[e].id]==1&&whe[c[e+1].id]==1&&whe[c[e+2].id]==1)//1
        {
        	dfs(q,w,e+3,r,left);
        }
        if(whe[c[e].id]==1&&whe[c[e+1].id]==1&&whe[c[e+2].id]==0)//2
        {
        	whe[c[e+2].id]=1;
        	dfs(q,w,e+3,r,left-1);
        	whe[c[e+2].id]=0;
        }
        if(whe[c[e].id]==1&&whe[c[e+1].id]==0&&whe[c[e+2].id]==1)//3
        {
        	whe[c[e+1].id]=1;
        	dfs(q,w,e+3,r,left-1);
        	whe[c[e+1].id]=0;
        }
        if(whe[c[e].id]==1&&whe[c[e+1].id]==0&&whe[c[e+2].id]==0)//4
        {
        	whe[c[e+1].id]=whe[c[e+2].id]=1;
        	dfs(q,w,e+3,r,left-2);
        	whe[c[e+1].id]=whe[c[e+2].id]=0;
        }
        if(whe[c[e].id]==0&&whe[c[e+1].id]==1&&whe[c[e+2].id]==1)//5
        {
        	whe[c[e].id]=1;
        	dfs(q,w,e+3,r,left-1);
        	whe[c[e].id]=0;
        }
        if(whe[c[e].id]==0&&whe[c[e+1].id]==1&&whe[c[e+2].id]==0)//6
        {
        	whe[c[e+2].id]=whe[c[e].id]=1;
        	dfs(q,w,e+3,r,left-2);
        	whe[c[e+2].id]=whe[c[e].id]=0;
        }
        if(whe[c[e].id]==0&&whe[c[e+1].id]==0&&whe[c[e+2].id]==1)//7
        {
        	whe[c[e+1].id]=whe[c[e].id]=1;
        	dfs(q,w,e+3,r,left-2);
        	whe[c[e+1].id]=whe[c[e].id]=0;
        }
        if(whe[c[e].id]==0&&whe[c[e+1].id]==0&&whe[c[e+2].id]==0)//8
        {
        	whe[c[e+1].id]=whe[c[e+2].id]=whe[c[e].id]=1;
        	dfs(q,w,e+3,r,left-3);
        	whe[c[e+1].id]=whe[c[e+2].id]=whe[c[e].id]=0;
        }        
    }
}
int main()
{
	ans=40000*40000+1;
	cin>>n;
	for(int i=1;i<=n;i++)
	{
		scanf("%d%d",&a[i].x,&a[i].y);
		a[i].id=b[i].id=c[i].id=d[i].id=i;
		b[i].x=c[i].x=d[i].x=a[i].x;
		b[i].y=c[i].y=d[i].y=a[i].y;
	}
	sort(a+1,a+1+n,comp1);
	sort(b+1,b+1+n,comp2);
	sort(c+1,c+1+n,comp3);
	sort(d+1,d+1+n,comp4);
    dfs(1,1,1,1,3);
	cout<<ans;
}
2020/5/16 07:36
加载中...