首页 技术 正文
技术 2022年11月14日
0 收藏 434 点赞 4,704 浏览 2387 个字

Texas Trip

Time Limit: 1000MS   Memory Limit: 65536K
Total Submissions: 4998   Accepted: 1559

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
题目大意:给你平面上的若干个点的坐标,让你求能将这些点覆盖的正方形的最小面积是多少。
思路分析:刚开始我一直搞不懂第二组样例怎么来的,我一直觉得是400,后来才想明白正方形是可以进行旋转的,
然后解题思路又好久没有想明白,这道题在题目分类是三分,一直不清楚到底应该怎么进行三分,后来想了一下
正方形的旋转不容易解决,但是我可以让坐标轴旋转啊,很明显在坐标轴旋转的过程中最小正方形的边长是先减后
增的趋势,为单峰函数,因此可以用三分法来进行解决。
代码:
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <queue>
#include <stack>
#include <cmath>
using namespace std;
const int maxn=35;
#define eps 1e-8
const int inf=0xfffffff;
const double pi=acos(-1.0);
struct nod
{
    int x;
    int y;
};
nod point[maxn];
int n;
double cul(double a)
{
    double minx=inf,maxx=-inf;
    double miny=inf,maxy=-inf;
    for(int i=0;i<n;i++)
    {
        double xx=point[i].x*cos(a)+point[i].y*sin(a);
        double yy=point[i].y*cos(a)-point[i].x*sin(a);
        minx=min(minx,xx),maxx=max(maxx,xx);
        miny=min(miny,yy),maxy=max(maxy,yy);
    }
    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("%d%d",&point[i].x,&point[i].y);
        double l=0.0,r=pi;
        double ans;
        while(l+eps<=r)
        {
            double mid=(l+r)/2;
            double mmid=(mid+r)/2;
            double t1=cul(mid),t2=cul(mmid);
            if(t1<=t2) r=mmid;
            else l=mid;
        }
        printf("%.2lf\n",cul(l)*cul(l));
    }
    return 0;
}
相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:9,492
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,907
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,740
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,495
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:8,133
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:5,297