poj3301

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

三分,不过不看题解谁知道是三分题,,,啊难过

而且三分的对象是坐标系,也就是说我们这题的目标是点不动让坐标系旋转,旋转之后把正对坐标系的正方形的最小面积求出来,找出哪个旋转角度的正对坐标轴的面积最小即为所求。其次让坐标系旋转的时候对应点的坐标会有改变,对应公式得记住:

X’ = x * cosa - y * sina;

y’ = y * cosa + x * sina;

然后对坐标旋转角度0到180三分,每次找出最大纵向距离和最大横向距离,要构成正方形的话就取纵向距离和横向距离的最大值呗!

这题主要是没思路,如果看了思路这题就成水题了。。。。。

代码:

#include <iostream>
#include<memory.h>
#include<math.h>
#include<stdio.h>
using namespace std;
struct data
{
    double x,y;
}a[1000];

int main()
{
    int t;
    cin>>t;
    while(t--)
    {
        memset(a,0,sizeof(a));
        int n;
        cin>>n;
        for(int i=0;i<n;i++)
            cin>>a[i].x>>a[i].y;
        double l=0,r=180,mid,midmid,MIN1,MIN2;
        while(fabs(r-l)>1e-8)
        {
            mid=(l+r)*0.5;
            midmid=(mid+r)*0.5;
            double maxx1=-100000000,
            maxx2=-100000000,maxy1=-100000000,
            maxy2=-100000000,minx1=100000000,
            minx2=100000000,miny1=100000000,
            miny2=10000000;
            for(int i=0;i<n;i++)
            {
                double t1=a[i].x*cos(mid)-a[i].y*sin(mid),
                t2=a[i].x*cos(midmid)-a[i].y*sin(midmid),
                t3=a[i].y*cos(mid)+a[i].x*sin(mid),
                t4=a[i].y*cos(midmid)+a[i].x*sin(midmid);
                maxx1=max(maxx1,t1);
                maxx2=max(maxx2,t2);
                minx1=min(minx1,t1);
                minx2=min(minx2,t2);
                maxy1=max(maxy1,t3);
                miny1=min(miny1,t3);
                maxy2=max(maxy2,t4);
                miny2=min(miny2,t4);
            }
            MIN1=max(maxx1-minx1,maxy1-miny1),
            MIN2=max(maxx2-minx2,maxy2-miny2);
            if(MIN1<=MIN2)
                r=midmid;
            else l=mid;
          //  cout<<l<<' '<<mid<<' '<<midmid<<' '<<r<<endl;
        }
        printf("%.2f\n",MIN1*MIN1);
    }
    return 0;
}



转载于:https://www.cnblogs.com/martinue/p/5490555.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值