POJ 3301 Texas Trip(三分)

本文介绍了一种算法,用于解决寻找能够覆盖一组特定整数格点的最小面积正方形的问题。通过旋转坐标系来找到最优解,确保了所求正方形的边与坐标轴平行,便于使用标准材料进行修补。

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

对坐标系进行(0, 180]度的旋转,然后每个点得到新的坐标,找到最上面,最下面,最左面和最右面的点,然后就行确定当前旋转角度的面积。

x' = x*cos(th) + y*sin(th);

y' = y*cos(th) - x*sin(th);

三分枚举角度。


Texas Trip
Time Limit: 1000MS Memory Limit: 65536K
Total Submissions: 3968 Accepted: 1195

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

Source

Waterloo Local Contest, 2007.7.14

#include <algorithm>
#include <iostream>
#include <stdlib.h>
#include <string.h>
#include <iomanip>
#include <stdio.h>
#include <string>
#include <queue>
#include <cmath>
#include <stack>
#include <map>
#include <set>
#define eps 1e-12
///#define M 1000100
#define LL __int64
///#define LL long long
///#define INF 0x7ffffff
#define INF 0x3f3f3f3f
#define PI 3.1415926535898
#define zero(x) ((fabs(x)<eps)?0:x)

using namespace std;

const int maxn = 510;
int n;

double p[maxn][2];

double Cir(double x)
{
    double minx, miny, maxx, maxy;
    double tmpx, tmpy;
    minx = miny = 60000.0;
    maxx = maxy = -60000.0;
    for(int i = 0; i < n; i++)
    {
        tmpx=p[i][0]*cos(x)-p[i][1]*sin(x);
        tmpy=p[i][1]*cos(x)+p[i][0]*sin(x);
        minx=min(tmpx,minx);
        miny=min(tmpy,miny);
        maxx=max(tmpx,maxx);
        maxy=max(tmpy,maxy);
    }
    return max(maxx-minx,maxy-miny);
}

int main()
{
    int T;
    cin >>T;
    while(T--)
    {
        cin >>n;
        for(int i = 0; i < n; i++) scanf("%lf %lf",&p[i][0], &p[i][1]);
        double l = 0,r = PI/2;
        double ll, rr;
        while(r-l > eps)
        {
            ll = (l*2+r)/3;
            rr = (l+r*2)/3;
            if(Cir(ll)>Cir(rr))
                l=ll;
            else
                r=rr;
        }
        printf("%.2lf\n",Cir(l)*Cir(l));
    }
    return 0;
}


评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值