ICPC 2019-2020 North-Western Russia Regional Contest I. Ideal Pyramid 几何思维题

首先四棱锥的朝向是固定的,设最终四棱锥的左边/右边在x轴左边l,r。前边和后边在y轴坐标为d,u

如下图,中心点坐标为  :(  (l+r)/2,(u+d)/2  )

ICPC 2019-2020 North-Western Russia Regional Contest I. Ideal Pyramid 几何思维题_第1张图片

所以对于一个点(x,y,h)。

最终四棱锥的l最大为x-h,r最小为x+h,u最小为y+h,d最大为y-h。

(拿l来说:如果最终四棱锥的l比x-h还大,那么点(x,y)处的高度就会小于h,可以在纸上画画想想立体空间)

所以问题转化为了,若干矩形,求一个最小矩形把它们包括在内。

然后遍历搞一搞就行

#include 
using namespace std;
typedef long long ll;
#define ls (o<<1)
#define rs (o<<1|1)
#define pb push_back
const double PI= acos(-1.0);
const int M = 1e5+7;

int head[M],cnt;
void init(){cnt=0,memset(head,0,sizeof(head));}
struct EDGE{int to,nxt,w;}ee[M*2];
void add(int x,int y,int w){ee[++cnt].nxt=head[x],ee[cnt].w=w,ee[cnt].to=y,head[x]=cnt;}



int main()
{
	ios::sync_with_stdio(false);
  	cin.tie(0);
  	int n;
  	cin>>n;
  	int l=1e9,r=-1e9,u=-1e9,d=1e9;
  	for(int i=1;i<=n;i++)
  	{
  		int x,y,h;
  		cin>>x>>y>>h;
  		l=min(l,x-h);
  		r=max(r,x+h);
  		d=min(d,y-h);
  		u=max(u,y+h);
	}
	//cout<

 

你可能感兴趣的:(#,计算几何)