80pts WA 求助
查看原帖
80pts WA 求助
380019
xieyikai2333楼主2021/11/13 11:55

第三个测试点挂了

INPUT:

9 2
0 4
0 2
1 3
2 4
2 2
2 0
3 1
4 2
4 0

STD_OUTPUT:

10

MY_OUTPUT:

8

MY_CODE:

#include <bits/stdc++.h>
using namespace std;
int x[505],y[505],n,k,ans=INT_MAX;
struct rec
{
	int xa,ya,xb,yb;
	bool used;
	int Get_S()
	{
		return (xb-xa)*(yb-ya); 
	}
	void Add(int x,int y)
	{
		if(!used)used=true,xa=xb=x,ya=yb=y;
		else
		{
			if(x>xb)xb=x;
			if(x<xa)xa=x;
			if(y>yb)yb=y;
			if(y<ya)ya=y;
		}
		return;
	}
	bool in_rec(int x,int y)
	{
		if(x>xb||x<xa||y>yb||y<ya)return false;
		return true;
	}
	bool cross(rec u)
	{
		if(!used||!u.used)return false;
		return u.in_rec(xa,ya)||u.in_rec(xa,yb)||u.in_rec(xb,ya)||u.in_rec(xb,yb);
	}
}g[4];
bool nc()
{
	for(int i=0;i<k;i++)
	{
		for(int j=n+1;j<k;j++)
		{
			if(g[i].cross(g[j])||g[j].cross(g[i]))return false;
		}
	}
	return true;
}
void dfs(int S,int step)
{
	if(S>=ans)return;
	if(step>n)
	{
		if(nc())ans=S;
		return;
	}
	for(int i=0;i<k;i++)
	{
		rec t=g[i];
		g[i].Add(x[step],y[step]);
		dfs(S-t.Get_S()+g[i].Get_S(),step+1);
		g[i]=t;
	}
	return;
}
int main()
{
//g[0].used=g[1].used=1;
//g[0].xa=0;
//g[0].ya=2;
//g[0].xb=2;
//g[0].yb=4;
//g[1].xa=2;
//g[1].ya=0;
//g[1].xb=4;
//g[1].yb=2;
//k=2;
//cout<<nc();
	cin>>n>>k;
	for(int i=1;i<=n;i++)cin>>x[i]>>y[i];
	dfs(0,1);
	cout<<ans;
	return 0;
}
2021/11/13 11:55
加载中...