zoukankan      html  css  js  c++  java
  • poj3301Texas Trip

    Texas Trip
    Time Limit: 1000MS   Memory Limit: 65536K
    Total Submissions: 3269   Accepted: 966

    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 followingn 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
    
    
    #include <iostream>
    #include <cstdio>
    #include <cmath>
    #include <algorithm>
    using namespace std;
    const double EPS = 1e-10;
    const double maxn=0xfffffffffffff;
    const double minn=-0xfffffffffffff;
    const double PI=acos(-1.0);
    
    double x[39],y[39];
    int n;
    
    
    
    double Cal(double a)
    {
    	double maxx=minn,minx=maxn,maxy=minn,miny=maxn;
    	for(int i=1;i<=n;i++)
    	{
    		double tx,ty;
    		tx=x[i]*cos(a)-y[i]*sin(a);
    		ty=y[i]*cos(a)+x[i]*sin(a);
    
    		maxx=max(maxx,tx);
    		minx=min(minx,tx);
    		maxy=max(maxy,ty);
    		miny=min(miny,ty);
    	}
    
    	return max(maxx-minx,maxy-miny);
    }
    
    double Solve(void)
    {
    	double Left, Right;
    	double mid, midmid;
    	double mid_value, midmid_value;
    	Left = 0; Right = PI;
    	while (Left + EPS < Right)
    	{
    		mid = (Left + Right) / 2;
    		midmid = (mid + Right) / 2;
    		mid_value = Cal(mid);
    		midmid_value = Cal(midmid);
    		if (mid_value <= midmid_value) Right = midmid;
    		else Left = mid;
    	}
    	return Cal(Left);
    }
    
    int main()
    {
    	freopen("in.txt","r",stdin);
    	int t;
    	cin>>t;
    	while(t--)
    	{
    		cin>>n;
    		for(int i=1;i<=n;i++)
    			cin>>x[i]>>y[i];
    		double ans = Solve();
    		printf("%.2lf\n",ans*ans);
    	}
    	return 0;
    }


  • 相关阅读:
    Kubernetes 升级过程记录:从 1.17.0 升级至最新版 1.20.2
    歼10:职业有个基本属性,为了糊口。然后再区分 主动 or 被动,被动者只是为了糊口,那自然是看不起自己的职业
    红胖子:写给人生的九封信,愿你的人生淡定从容,繁华似锦!!!
    Embarcadero MVP(68位,全部都有个人主页)
    Delphi 26 岁
    C# Assembly 与 Reflection
    你精通那么多技术,为何还是做不好一个项目
    Linux 6 个“吓人”的 命令
    Distributed Application runtime
    RocketMQ and kafka
  • 原文地址:https://www.cnblogs.com/lgh1992314/p/5835343.html
Copyright © 2011-2022 走看看