upc- 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.

输入

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 three integers x, y, h — the coordinates of the center (x, y) of the optimal pyramid and its height.

样例输入
【样例1】
1
0 0 5
【样例2】
2
3 3 3
6 6 2
样例输出
【样例1】
0 0 5
【样例2】
4 4 4
题意

给你 n 个柱子( 坐标 + 高度 ),让你找到一个最小的金字塔可以把 n 个柱子都装进去(金字塔底部正方形,坡度正好 45 度),输出金字塔的中心坐标跟高度

思路

根据每个柱子的坐标以及高度确定整个金字塔的边界( 可以根据45度确定一个柱子的边界: x : [ x - h , x + h ],y : [ y - h , y + h ] , 进而得到所有柱子公共的边界即金字塔边界),金字塔中心坐标就是边界坐标的中值 。
关于金字塔的高度,我们可以根据45度的特性来得到,如果45度,高和底面正方形的边(之前确定的边界中长的为正方形的边)的一半是相等的 , 因为高要求是整数,所以若边长为奇数,则高度 + 1 ,偶数不加。(最后记得long long ,可把我wa傻了/(ㄒoㄒ)/~~)

代码
#include<iostream>
#include<string>
#include<map>
#include<set>
//#include<unordered_map>
#include<queue>
#include<cstdio>
#include<vector>
#include<cstring>
#include<algorithm>
#include<iomanip>
#include<cmath>
#include<fstream>
#define X first
#define Y second
#define best 131 
#define INF 0x3f3f3f3f3f3f3f3f
#define P pair<int,int>
#define lowbit(x) x & -x
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const double eps=1e-7;
const double pai=acos(-1.0);
const int N=2e4+10;
const int maxn=1e5+10;
const int mod=1e9+7;
int n,minn1=INF,minn2=INF,maxx1=-INF,maxx2=-INF,ans;
struct node
{
    int x;
    int y;
    int h;
}a[1010];
int main()
{
    //ios::sync_with_stdio(false);
    scanf("%d",&n);
    for(int i=1;i<=n;i++) scanf("%d%d%d",&a[i].x,&a[i].y,&a[i].h);
    for(int i=1;i<=n;i++)
    {
        if(minn1>a[i].x-a[i].h) minn1=a[i].x-a[i].h;
        if(minn2>a[i].y-a[i].h) minn2=a[i].y-a[i].h;
        if(maxx1<a[i].x+a[i].h) maxx1=a[i].x+a[i].h;
        if(maxx2<a[i].y+a[i].h) maxx2=a[i].y+a[i].h;
    }
    if(maxx1-minn1>=maxx2-minn2)
    {
        ll ans=(maxx1-minn1)/2;
        if((maxx1-minn1)%2) ans++;
        printf("%lld %lld %lld\n",(ll)(minn1+maxx1)/2,(ll)(minn2+maxx2)/2,ans);
    }
    else
    {
        ll ans=(maxx2-minn2)/2;
        if((maxx2-minn2)%2) ans++;
        printf("%lld %lld %lld\n",(ll)(minn1+maxx1)/2,(ll)(minn2+maxx2)/2,ans);
    }
    return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值