poj_3301_三分_凹函数_求能覆盖N个点的最小正方形_对坐标系旋转_求新坐标
2017-08-22 10:57
459 查看
Texas Trip
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
Source
Waterloo Local Contest, 2007.7.14
题意:给你n个点求能覆盖所有点的最小正方形
思路:
求出旋转后的最大和最小的点 ,就是可以求出旋转后的新坐标.
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
Source
Waterloo Local Contest, 2007.7.14
题意:给你n个点求能覆盖所有点的最小正方形
草稿记录 自己推一下
思路:
求出旋转后的最大和最小的点 ,就是可以求出旋转后的新坐标.
#include<iostream> #include<cstdio> #include<cmath> #include<algorithm> using namespace std; #define pi acos(-1.0) #define eps 1e-8 const int inf=999999999; double x[511],y[511]; int n; double val(double tt) { double mx=-inf,my=-inf,nx=inf,ny=inf; for(int i=0;i<n;i++) { double tx=x[i]*cos(tt)-y[i]*sin(tt); double ty=x[i]*sin(tt)+y[i]*cos(tt); mx=max(mx,tx); nx=min(nx,tx); my=max(my,ty); ny=min(ny,ty); } return max((mx-nx),(my-ny)); } double solve(double l,double r ) { while(r-l>eps ) { double ll=(r+l)/2.0; double rr=(ll+r)/2.0; if(val(ll)>val(rr)) l=ll; else r=rr; } return val(l); } int main() { int t,i,j; while(cin>>t) { while(t--) { scanf("%d",&n); for(i=0;i<n;i++) scanf("%lf%lf",&x[i],&y[i]); double l=0.0,r=pi/2.0; double ans=solve(l,r); printf("%.2lf\n",ans*ans); } } return 0; }
相关文章推荐
- POJ 3301 (坐标变换、三分枚举计算 点集最小正方形覆盖)
- POJ 3301 Texas Trip(最小正方形覆盖、点坐标旋转)
- POJ 3301 三分(最小覆盖正方形)
- POJ 3301 Texas Trip(最小正方形覆盖+三分)
- poj 3301 Texas Trip(旋转+三分)
- 度度熊有一张网格纸,但是纸上有一些点过的点,每个点都在网格点上,若把网格看成一个坐标轴平行于网格线的坐标系的话,每个点可以用一对整数x,y来表示。度度熊必须沿着网格线画一个正方形,使所有点在正方形的内部或者边界。然后把这个正方形剪下来。问剪掉正方形的最小面积是多少。
- poj 1325 Machine Schedule(最小点覆盖即最大匹配,匈牙利算法)
- POJ 3216 Repairing Company(最小路径覆盖)
- poj 3041 Asteroids( 最小顶点覆盖,二分图)
- poj 1422 Air Raid 最小路径覆盖
- poj 3308(最小点权覆盖、最小割)
- POJ 3041 Asteroids (最小点覆盖)
- POJ 2226 Muddy Fields【二分图最小点覆盖】
- 【POJ】3308 Paratroopers 化乘为加——最小点权覆盖
- POJ 3020 Antenna Placement (最小边覆盖)
- BZOJ1185 [HNOI2007]最小矩形覆盖(旋转卡壳)
- Poj 3020 Antenna Placement【最小边覆盖 匈牙利算法】
- poj 2226 还是最小点覆盖的匹配问题
- poj2594 Treasure Exploration(可相交最小路径覆盖)
- POJ 1325 简单基础匈牙利二分匹配:最小点覆盖