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;
}

poj3301 三分的更多相关文章

  1. poj3301 Texas Trip【三分算法】

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

  2. hdu3714 三分找最值

    Error Curves Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Tota ...

  3. BZOJ 1857 传送带 (三分套三分)

    在一个2维平面上有两条传送带,每一条传送带可以看成是一条线段.两条传送带分别为线段AB和线段CD.lxhgww在AB上的移动速度为P,在CD上的移动速度为Q,在平面上的移动速度R.现在lxhgww想从 ...

  4. hdu 4717(三分求极值)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4717 思路:三分时间求极小值. #include <iostream> #include ...

  5. HDU2438 数学+三分

    Turn the corner Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)T ...

  6. 三分之一的程序猿之社交类app踩过的那些坑

    三分之一的程序猿之社交类app踩过的那些坑 万众创新,全民创业.哪怕去年陌生人社交不管融资与否都倒闭了不知道多少家,但是依然有很多陌生人社交应用层出不穷的冒出来.各种脑洞大开,让人拍案叫起. 下面我们 ...

  7. 基于jPlayer的三分屏制作

    三分屏,这里的三分屏只是在一个播放器里同时播放三个视频,但是要求只有一个控制面板同时控制它们,要求它们共享一个时间轨道.这次只是简单的模拟了一下功能,并没有深入的研究. 首先,需要下载jPlayer, ...

  8. 【BZOJ-1857】传送带 三分套三分

    1857: [Scoi2010]传送带 Time Limit: 1 Sec  Memory Limit: 64 MBSubmit: 1077  Solved: 575[Submit][Status][ ...

  9. ACM : HDU 2899 Strange fuction 解题报告 -二分、三分

    Strange fuction Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Tot ...

随机推荐

  1. 《python基础教程》笔记之 更加抽象

    方法.函数和特性 函数和方法的区别在于self参数,方法(绑定方法)将它们的第一个参数帮顶到所属的实例上,因此这个参数可以不必提供.可以将特性绑定到一个普通函数上,这样就不会有特殊的self参数了,换 ...

  2. 关于linux定时操作cron的理解

    cron是服务名称,crond是后台进程(有的后台也叫作cron,本人是ubuntu12.04,32bit),crontab则是定制好的计划任务表. 软件包安装: 要使用cron服务,先要安装vixi ...

  3. $parse , $interpolate ,$complie , $destroy

    $parse 是angular 提供的javascript解析器 . var getter = $parse(expression); var setter = getter.assign; cont ...

  4. PYTHON线程知识再研习D---可重入锁

    不多解释,预防普通锁不正规的获取与释放 #!/usr/bin/env python # -*- coding: utf-8 -*- import threading import time class ...

  5. linux文件合并

    第一:两个文件的交集,并集前提条件:每个文件中不得有重复行1. 取出两个文件的并集(重复的行只保留一份)2. 取出两个文件的交集(只留下同时存在于两个文件中的文件)3. 删除交集,留下其他的行1. c ...

  6. linux磁盘限额配置:quota命令

    LINUX下也有类似WINDOWS NTFS所用的磁盘限额,用的是quota来实现通过rpm -q quota确定是否已安装用quota只能对patation做限额,要做到针对某个目录来做只能靠ln ...

  7. Linux企业级项目实践之网络爬虫(4)——主程序流程

    当我们设计好程序框架之后就要开始实现它了.第一步当然是要实现主程序的流程框架.之后我们逐渐填充每个流程的细节和其需要调用的模块. 主程序的流程如下: 1.  解析命令行参数,并根据参数跳转到相应的处理 ...

  8. vs2008包加载失败

    由于安装vs2008sp1后,新建项目报错,解决未遂,于是重装vs2008,装完后又出现包加载失败问题: Microsoft.Data.Entity.Design.Package.MicrosoftD ...

  9. Oracle中对列加密的方法

    Oracle中对列加密的方法 2011-12-22 17:21:13 分类: Linux Oracle支持多种列加密方式: 1,透明数据加密(TDE):create table encrypt_col ...

  10. MVC4.0系统开发新手历程(二)

    登录页 首先声明登录页不是我开发完成的 所以就简单的发下供大家参考 思路:由于是奖金系统,里面涉及到Money,所以在验证方面上下了很大的功夫,我看了下 主要的思想是 获取到那几个人会用到这个系统,然 ...