(POJ - 3301)Texas Trip

本文介绍了一种算法,用于解决寻找最小面积正方形以覆盖平面上指定点集的问题。通过坐标旋转和三分法确定最优正方形边长。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

(POJ - 3301)Texas Trip

Time Limit: 1000MS Memory Limit: 65536K
Total Submissions: 5943 Accepted: 1839

Description

After a day trip with his friend Dick, Harry noticed a strange pattern of tiny holes in the door of his SUV. The local American Tire store sells fiberglass patching material only in square sheets. What is the smallest patch that Harry needs to fix his door?

Assume that the holes are points on the integer lattice in the plane. Your job is to find the area of the smallest square that will cover all the holes.

Input

The first line of input contains a single integer T expressed in decimal with no leading zeroes, denoting the number of test cases to follow. The subsequent lines of input describe the test cases.

Each test case begins with a single line, containing a single integer n expressed in decimal with no leading zeroes, the number of points to follow; each of the following n lines contains two integers x and y, both expressed in decimal with no leading zeroes, giving the coordinates of one of your points.

You are guaranteed that T ≤ 30 and that no data set contains more than 30 points. All points in each data set will be no more than 500 units away from (0,0).

Output

Print, on a single line with two decimal places of precision, the area of the smallest square containing all of your points.

Sample Input

2
4
-1 -1
1 -1
1 1
-1 1
4
10 1
10 -1
-10 1
-10 -1

Sample Output

4.00
242.00

题目大意:平面上有n个点,求一个面积最小的正方形,使得这个正方形可以覆盖所有点。

思路:首先要知道平面坐标旋转公式,已知一个点p(x,y),若坐标轴逆时针旋转θ角度,得到点p坐标为(x1,y1)。则x1=xcosθysinθ,y1=ycosθ+xsinθ。对于坐标旋转的解释见下图:
这里写图片描述
知道坐标旋转公示后,我们自然而然会去想去三分角度,对于每一个旋转角度,都有一个x轴方向距离最远的两点maxx和y轴上距离最远的两点maxy,而正方形的边长就是max{maxxmaxy},随着旋转角度的增加,这个边长必然会有一个最小值,即当maxx=maxy时取到最小值,这个便是我们要求的答案。

#include<cstdio>
#include<algorithm>
#include<cmath>
using namespace std;

const int INF=0x3f3f3f3f;
const double eps=1e-8;
const double pi=acos(-1.0);
const int maxn=35;
int n;

struct node
{
    double x,y;
}a[maxn];

double check(double t)
{
    double maxx=-INF,minx=INF,maxy=-INF,miny=INF;
    for(int i=0;i<n;i++)
    {
        double tmpx=a[i].x*cos(t)-a[i].y*sin(t);
        maxx=max(maxx,tmpx);
        minx=min(minx,tmpx);
        double tmpy=a[i].y*cos(t)+a[i].x*sin(t);
        maxy=max(maxy,tmpy);
        miny=min(miny,tmpy);
    }
    return max(maxx-minx,maxy-miny);
}

int main()
{
    int T;
    scanf("%d",&T);
    while(T--)
    {
        scanf("%d",&n);
        for(int i=0;i<n;i++) scanf("%lf%lf",&a[i].x,&a[i].y);
        double lo=0,hi=pi/2.0,mid,midmid;
        while(hi-lo>eps)
        {
            mid=(hi+lo)/2.0;
            midmid=(hi+mid)/2.0;
            if(check(mid)<check(midmid)) hi=midmid;
            else lo=mid;
        }
        double ans=check(lo)*check(lo);
        printf("%.2f\n",ans);
    }
    return 0;
}
内容概要:本文档是Kenwood TK-6110 VHF FM收发器的操作手册,详细介绍了设备的基本功能、安装步骤和操作指南。手册首先感谢用户选择Kenwood产品,并强调了设备的安全性和合规性,包括FCC警告和政府法律禁止未经授权的无线电台操作。接着,手册逐步指导用户进行设备的拆箱检查、安装准备(如工具、电源连接)、安装步骤以及熟悉设备的前面板、后面板和麦克风布局。此外,还涵盖了基本操作(如开关机、音量调整、频道选择和通话)以及辅助功能(如定时断电、忙道锁定、双音多频呼叫等)。最后,提供了关于DTMF呼叫(手动拨号、重拨、自动拨号)的具体操作步骤。 适合人群:适用于需要使用Kenwood TK-6110 VHF FM收发器的专业用户或技术人员,特别是那些负责安装和维护移动通信设备的人员。 使用场景及目标:①帮助用户正确安装和配置Kenwood TK-6110 VHF FM收发器,确保其在车辆或其他移动平台上安全可靠地运行;②指导用户掌握设备的基本操作技能,如频道选择、通话、信号发送等;③提供详细的辅助功能设置说明,使用户能够充分利用设备的各种高级功能,如定时断电、忙道锁定、双音多频呼叫等。 其他说明:用户应仔细阅读并遵守所有安全警告和操作指南,以避免潜在的危害和法律问题。建议在安装和使用过程中咨询授权经销商或专业技术人员,以确保设备的正常运行和最佳性能。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值