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 ≤  and that no data set contains more than  points. All points in each data set will be no more than  units away from (,).

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


- -
- - -
-
- -

Sample Output

4.00
242.00

Source

 
这里要知道坐标旋转公式:
如果为旋转前的坐标,为旋转后的坐标,那么有:
 
 
然后对给定的所以点进行旋转,范围为[0,PI/2.0],通过三分搜索找到最小的边长,这里用三分搜索是因为旋转函数是一个单峰函数,然后就可以得出答案了。
 
 #pragma comment(linker, "/STACK:1024000000,1024000000")
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<math.h>
#include<algorithm>
#include<queue>
#include<set>
#include<bitset>
#include<map>
#include<vector>
#include<stdlib.h>
#include <stack>
using namespace std;
int dirx[]={,,-,};
int diry[]={-,,,};
#define PI acos(-1.0)
#define max(a,b) (a) > (b) ? (a) : (b)
#define min(a,b) (a) < (b) ? (a) : (b)
#define ll long long
#define eps 1e-10
#define MOD 1000000007
#define N 36
#define inf 1<<26 int n;
struct Node{
double x,y;
}node[N];
double cal(double a){
double sx=inf;
double sy=inf;
double ex=-inf;
double ey=-inf;
for(int i=;i<n;i++){
double x1=node[i].x*cos(a)-node[i].y*sin(a);
double y1=node[i].y*cos(a)+node[i].x*sin(a);
sx=min(sx,x1);
ex=max(ex,x1);
sy=min(sy,y1);
ey=max(ey,y1);
} return max(ex-sx,ey-sy); }
int main()
{
int t;
scanf("%d",&t);
while(t--){
scanf("%d",&n);
for(int i=;i<n;i++){
scanf("%lf%lf",&node[i].x,&node[i].y);
}
double low=;
double high=PI/2.0;
while((high-low)>eps){
double mid1=(*low+high)/;
double mid2=(low+*high)/;
double ans1=cal(mid1);
double ans2=cal(mid2);
if(ans1<ans2){
high=mid2;
}
else{
low=mid1;
}
} printf("%.2lf\n",cal(low)*cal(low));
}
return ;
}

poj 3301 Texas Trip(几何+三分)的更多相关文章

  1. POJ 3301 Texas Trip (三分)

    题目链接 题意 : 给你若干个点,让你找最小的正方形覆盖这所有的点.输出面积. 思路 : 三分枚举正方形两对边的距离,然后求出最大,本题用的是旋转正方形,也可以用旋转点,即点的相对位置不变. 正方形从 ...

  2. 三分 --- POJ 3301 Texas Trip

    Texas Trip Problem's Link:   http://poj.org/problem?id=3301 Mean: 给定n(n <= 30)个点,求出包含这些点的面积最小的正方形 ...

  3. poj 3301 Texas Trip 三分法

    思路:三分法求解凸函数的极值,三分法介绍在这:http://hi.baidu.com/czyuan_acm/item/81b21d1910ea729c99ce33db 很容易就可以推出旋转后的坐标: ...

  4. POJ 3301 Texas Trip

    题目大意: 在二维坐标系中给出一些点.求能覆盖他们的最小正方形的面积(正方形的边不一定平行坐标轴) 解题思路: 对于一个点.若坐标轴旋转a度(弧度制).那么X'=X*cos(a)-Y*sin(a);Y ...

  5. poj3301 Texas Trip【三分算法】

    题目地址:http://poj.org/problem?id=3301 简述:T组测试数据,每组线输入n,代表有n个点,接下来输入这n个点的坐标,坐标都是整数. 要求用一个最小的正方形覆盖所有的点,输 ...

  6. POJ 3301:Texas Trip(计算几何+三分)

    http://poj.org/problem?id=3301 题意:在二维平面上有n个点,每个点有一个坐标,问需要的正方形最小面积是多少可以覆盖所有的点. 思路:从第二个样例可以看出,将正方形旋转45 ...

  7. POJ 3301 三分(最小覆盖正方形)

    题意:      给你n个点,让你找一个最小的正方形去覆盖所有点.思路:       想一下,如果题目中规定正方形必须和x轴平行,那么我们是不是直接找到最大的x差和最大的y差取最大就行了,但是这个题目 ...

  8. POJ3301 Texas Trip 计算几何、随机化贪心

    传送门--Vjudge 三分写法似乎有问题,可以去Udebug上看Morass的\(666\)个测试点的数据,我的乱搞有很多比正解答案小,但还是能在SPOJ和POJ过,可见数据之水. 可以对正方形的角 ...

  9. URAL 1988 - Planet Ocean Landing【几何&三分答案】

    [题意] 在一个星球(是一个球体)表面有一个飞机(坐标(x1,y1,z1),原点是星球中心),在空中有一个空间站(坐标(x2,y2,z2)),所有值均小于100,现在要使飞机与空间站相遇,飞机的速度是 ...

随机推荐

  1. Android核心基础(十)

    1.音频采集 你可以使用手机进行现场录音,实现步骤如下: 第一步:在功能清单文件AndroidManifest.xml中添加音频刻录权限: <uses-permission android:na ...

  2. FlexComboBoxTree

    在我的CSDN资源中有项目工程文件.下载导入工程即可看到效果,下面是地址. http://download.csdn.net/detail/cym_lmy/6326053 MyCombBoxTree1 ...

  3. JQuery 补充

    筛选: expr         String 字符串值,包含供匹配当前元素集合的选择器表达式. jQuery      objectobject 现有的jQuery对象,以匹配当前的元素. elem ...

  4. [转]Laravel 4之控制器

    Laravel 4之控制器 http://dingjiannan.com/2013/laravel-controller/ 控制器 通常Laravel控制器文件放在app/controllers/目录 ...

  5. Linux :: vi E212: Can't open file for writing

    Linux :: vi E212: Can't open file for writing sysct1.conf 可能无写权限!查看方法:ls -lh /etc/sysct1.conf如果没有,则c ...

  6. javascript 多图无缝切换

    思路只要是ul移动前,首先将当前显示的li克隆岛ul最后,当每次运动执行完毕后,再将前面的li删除,如此循环. <!DOCTYPE html> <html> <head& ...

  7. 一个项目涉及到的50个Sql语句(整理版)

    /* 标题:一个项目涉及到的50个Sql语句(整理版) 说明:以下五十个语句都按照测试数据进行过测试,最好每次只单独运行一个语句. */ --1.学生表Student(S,Sname,Sage,Sse ...

  8. UILable文本常见属性说明

    1.text:设置标签显示文本. 2.attributedText:设置标签属性文本. NSString *text = @"first"; NSMutableAttributed ...

  9. javascript父窗口与子窗口通信

    在父窗口的js代码 //回调的函数 function alt(temp){ alert(temp); }; $("#Btn").click(function (obj) { //声 ...

  10. [转载]OpenSUSE 13.2/13.1 安装搜狗拼音输入法

    1. 添加 M17N 源: 13.2: sudo zypper ar -f http://download.opensuse.org/repositories/M17N/openSUSE_13.2/ ...