(POJ - 3301)Texas Trip

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

(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;
}
这个是完整源码 python实现 Flask,Vue 【python毕业设计】基于Python的Flask+Vue物业管理系统 源码+论文+sql脚本 完整版 数据库是mysql 本文首先实现了基于Python的Flask+Vue物业管理系统技术的发展随后依照传统的软件开发流程,最先为系统挑选适用的言语和软件开发平台,依据需求分析开展控制模块制做和数据库查询构造设计,随后依据系统整体功能模块的设计,制作系统的功能模块图、E-R图。随后,设计框架,依据设计的框架撰写编码,完成系统的每个功能模块。最终,对基本系统开展了检测,包含软件性能测试、单元测试和性能指标。测试结果表明,该系统能够实现所需的功能,运行状况尚可并无明显缺点。本文首先实现了基于Python的Flask+Vue物业管理系统技术的发展随后依照传统的软件开发流程,最先为系统挑选适用的言语和软件开发平台,依据需求分析开展控制模块制做和数据库查询构造设计,随后依据系统整体功能模块的设计,制作系统的功能模块图、E-R图。随后,设计框架,依据设计的框架撰写编码,完成系统的每个功能模块。最终,对基本系统开展了检测,包含软件性能测试、单元测试和性能指标。测试结果表明,该系统能够实现所需的功能,运行状况尚可并无明显缺点。本文首先实现了基于Python的Flask+Vue物业管理系统技术的发展随后依照传统的软件开发流程,最先为系统挑选适用的言语和软件开发平台,依据需求分析开展控制模块制做和数据库查询构造设计,随后依据系统整体功能模块的设计,制作系统的功能模块图、E-R图。随后,设计框架,依据设计的框架撰写编码,完成系统的每个功能模块。最终,对基本系统开展了检测,包含软件性能测试、单元测试和性能指标。测试结果表明,该系统能够实现所需的功能,运行状况尚可并无明显缺点。本文首先实现了基于Python的Flask+Vue物业管理系统技术的发
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值