博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

[poj][3301][Texas Trip]

Posted on 2012-07-12 13:55  紫华弦筝  阅读(157)  评论(0编辑  收藏  举报

题目:http://poj.org/problem?id=3301

View Code
#include <cstdio>
#include <cmath>
#include <cstring>
#include <algorithm>

using namespace std;

const double M = 1e99;
const double pi = acos(-1.0);
const double eps = 1e-8;

struct node
{
    double x, y;
    void get(){ scanf("%lf%lf", &x, &y); }
}p[40];

int T, n;

double len(double f){
    double l=M, r=-M, d=M, u=-M, x, y;
    for (int i=0; i<n; i++){
        x = cos(f)*p[i].x - sin(f)*p[i].y;
        y = sin(f)*p[i].x + cos(f)*p[i].y;
        l = min(l, x); r = max(r, x);
        d = min(d, y); u = max(u, y);
    }
    return max(r-l, u-d);
}

void solve(){
    double mid, midmid, lef, rig;
    for (lef=0, rig=pi/2; lef+eps<=rig;){
        mid = (lef + rig) / 2;
        midmid = (mid + rig) / 2;
        if (len(mid)>=len(midmid))lef=mid;
        else rig=midmid;
    }
    printf("%.2f\n", len(lef)*len(lef));
}

int main()
{
    //freopen("D:/10101441/a.txt", "r", stdin);
    scanf("%d", &T);
    while (T--){
        scanf("%d", &n);
        for (int i=0; i<n; i++)p[i].get();
        solve();
    }
    return 0;
}