I. Ideal Pyramid

Every pharaoh cares about his legacy. Reigning pharaoh Inaros the Great wants to be remembered for a long time. He is going to build the largest pyramid the humankind has ever seen.
Of course, the proper pyramid should have four sides at the bottom, oriented to the cardinal directions — two sides of the pyramid should go exactly from north to south, and two sides should go from east to west. The perfectly balanced pyramid should have the slope angle of the side equal to 45∘, no more, no less. To simplify construction, the pyramid should have integer height and integer coordinates of the center.
There are n obelisks at the construction site. The i-th obelisk is a pillar with coordinates (xi,yi) and height hi. Inaros wants to build a pyramid so that each existing obelisk would be inside the pyramid. The obelisk is inside the pyramid if the height of the pyramid at the obelisk position is greater than or equal to the height of the obelisk.
Since the pharaoh wants to finish the construction of the pyramid during his life, he wants to find the smallest possible pyramid that contains all of the obelisks.

Input
The first line contains a single integer n — the number of obelisks (1≤n≤1000).
Each of the following n lines contains three integers xi,yi,hi — the coordinates of the i-th obelisk and its height (−108≤xi,yi≤108; 1≤hi≤108).

Output
Output three integers x,y,h — the coordinates of the center (x,y) of the optimal pyramid and its height.

Examples
inputCopy
1
0 0 5
outputCopy
0 0 5
inputCopy
2
3 3 3
6 6 2
outputCopy
4 4 4

#include<bits/stdc++.h>
using namespace std;
#define maxn 1010
#define eps (1e-6)
typedef long long ll;
const int INF=(1e9)+10;
struct Point{
	int x,y,h;
}p[maxn];
int main(){
	int n; scanf("%d",&n);
	for(int i=1;i<=n;i++) scanf("%d%d%d",&p[i].x,&p[i].y,&p[i].h);
	if(n==1){
		printf("%d %d %d\n",p[1].x,p[1].y,p[1].h);
		return 0;
	}
	int mix=INF,miy=INF,mxx=-INF,mxy=-INF;
	for(int i=1;i<=n;i++){
		mix=min(mix,p[i].x-p[i].h);
		mxx=max(mxx,p[i].x+p[i].h);
		miy=min(miy,p[i].y-p[i].h);
		mxy=max(mxy,p[i].y+p[i].h);
	}
	if((mxx-mix)>=(mxy-miy)){
		mxy+=(mxx-mix)-(mxy-miy);
		if((mxx-mix)%2){
			mxx+=1; mxy+=1;
		}
		printf("%d %d %d\n",(mix+mxx)/2,(miy+mxy)/2,(mxx-mix)/2);
	}
	else{
		mxx+=(mxy-miy)-(mxx-mix);
		if((mxx-mix)%2){
			mxx+=1; mxy+=1;
		}
		printf("%d %d %d\n",(mix+mxx)/2,(miy+mxy)/2,(mxx-mix)/2);
	}
	return 0;
}
发布了444 篇原创文章 · 获赞 15 · 访问量 1万+

猜你喜欢

转载自blog.csdn.net/zt2650693774/article/details/102978115