poj 3301 Texas Trip(几何+三分)
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 ≤ and that no data set contains more than points. All points in each data set will be no more than units away from (,).
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
- -
- - -
-
- -
Sample Output
4.00
242.00
Source
#pragma comment(linker, "/STACK:1024000000,1024000000")
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<math.h>
#include<algorithm>
#include<queue>
#include<set>
#include<bitset>
#include<map>
#include<vector>
#include<stdlib.h>
#include <stack>
using namespace std;
int dirx[]={,,-,};
int diry[]={-,,,};
#define PI acos(-1.0)
#define max(a,b) (a) > (b) ? (a) : (b)
#define min(a,b) (a) < (b) ? (a) : (b)
#define ll long long
#define eps 1e-10
#define MOD 1000000007
#define N 36
#define inf 1<<26 int n;
struct Node{
double x,y;
}node[N];
double cal(double a){
double sx=inf;
double sy=inf;
double ex=-inf;
double ey=-inf;
for(int i=;i<n;i++){
double x1=node[i].x*cos(a)-node[i].y*sin(a);
double y1=node[i].y*cos(a)+node[i].x*sin(a);
sx=min(sx,x1);
ex=max(ex,x1);
sy=min(sy,y1);
ey=max(ey,y1);
} return max(ex-sx,ey-sy); }
int main()
{
int t;
scanf("%d",&t);
while(t--){
scanf("%d",&n);
for(int i=;i<n;i++){
scanf("%lf%lf",&node[i].x,&node[i].y);
}
double low=;
double high=PI/2.0;
while((high-low)>eps){
double mid1=(*low+high)/;
double mid2=(low+*high)/;
double ans1=cal(mid1);
double ans2=cal(mid2);
if(ans1<ans2){
high=mid2;
}
else{
low=mid1;
}
} printf("%.2lf\n",cal(low)*cal(low));
}
return ;
}
poj 3301 Texas Trip(几何+三分)的更多相关文章
- POJ 3301 Texas Trip (三分)
题目链接 题意 : 给你若干个点,让你找最小的正方形覆盖这所有的点.输出面积. 思路 : 三分枚举正方形两对边的距离,然后求出最大,本题用的是旋转正方形,也可以用旋转点,即点的相对位置不变. 正方形从 ...
- 三分 --- POJ 3301 Texas Trip
Texas Trip Problem's Link: http://poj.org/problem?id=3301 Mean: 给定n(n <= 30)个点,求出包含这些点的面积最小的正方形 ...
- poj 3301 Texas Trip 三分法
思路:三分法求解凸函数的极值,三分法介绍在这:http://hi.baidu.com/czyuan_acm/item/81b21d1910ea729c99ce33db 很容易就可以推出旋转后的坐标: ...
- POJ 3301 Texas Trip
题目大意: 在二维坐标系中给出一些点.求能覆盖他们的最小正方形的面积(正方形的边不一定平行坐标轴) 解题思路: 对于一个点.若坐标轴旋转a度(弧度制).那么X'=X*cos(a)-Y*sin(a);Y ...
- poj3301 Texas Trip【三分算法】
题目地址:http://poj.org/problem?id=3301 简述:T组测试数据,每组线输入n,代表有n个点,接下来输入这n个点的坐标,坐标都是整数. 要求用一个最小的正方形覆盖所有的点,输 ...
- POJ 3301:Texas Trip(计算几何+三分)
http://poj.org/problem?id=3301 题意:在二维平面上有n个点,每个点有一个坐标,问需要的正方形最小面积是多少可以覆盖所有的点. 思路:从第二个样例可以看出,将正方形旋转45 ...
- POJ 3301 三分(最小覆盖正方形)
题意: 给你n个点,让你找一个最小的正方形去覆盖所有点.思路: 想一下,如果题目中规定正方形必须和x轴平行,那么我们是不是直接找到最大的x差和最大的y差取最大就行了,但是这个题目 ...
- POJ3301 Texas Trip 计算几何、随机化贪心
传送门--Vjudge 三分写法似乎有问题,可以去Udebug上看Morass的\(666\)个测试点的数据,我的乱搞有很多比正解答案小,但还是能在SPOJ和POJ过,可见数据之水. 可以对正方形的角 ...
- URAL 1988 - Planet Ocean Landing【几何&三分答案】
[题意] 在一个星球(是一个球体)表面有一个飞机(坐标(x1,y1,z1),原点是星球中心),在空中有一个空间站(坐标(x2,y2,z2)),所有值均小于100,现在要使飞机与空间站相遇,飞机的速度是 ...
随机推荐
- Ubuntu Eclipse的Tomcat小问题:不能输入server name,不能启动tomcat
Ubuntu的Eclipse上安装Tomcat环境,这是让人烦啊,万幸还是终于解决了. Eclipse上Tomcat的搭建: 1.点击Eclipse上的菜单:Windows - Preference, ...
- 雅虎工程师初始化css
/*css reset code */ /**** 文字大小初始化,使1em=10px *****/ body { font-size:62.5%; } /* for IE/Win */ html&g ...
- Python 协程(gevent)
协程,又叫微线程,协程是一种用户态的轻量级线程. 协程拥有自己的寄存器上下文和栈.协程调度切换时,将寄存器上下文和栈保存到其他地方,在切回来的时候,恢复先前保存的寄存器上下文和栈.因此: 协程能保留上 ...
- XShell连接CentOS 7.2显示中文乱码问题的解决方法
背景 使用U盘往Windows主机.Linux主机传文件还是经常的事,但有时候文件名有中文, 传到Linux机器会有乱码,选择起来也很麻烦,最近刚好遇到,写下解决方法. 环境 Linux [root@ ...
- python list 按长度分段
def changes(a,b): #list 分段函数,a:数据[(1),(2)]b:长度 for i in xrange(0,len(a),b): yield a[i:i+b] for i in ...
- nginx 采用https 协议通信配置
在网络通信中,使用抓包软件可以对网络请求进行分析,并进行重放攻击,重放攻击的解决方案一般是使用一个变化的参数,例如RSA加密的时间戳,但考虑到网络传输时延,时间戳需要有一定的误差容限,这样仍然不能从根 ...
- VC调试笔记
1.windows-32调试: ①使用map文件根据崩溃地址寻找对应的源代码文件和行号 勾选project->settings->link->General mapfile,对应的P ...
- Qt之操作Excel
Visual Basic for Applications(VBA)是一种Visual Basic的一种宏语言,主要能用来扩展Windows的应用程式功能,特别是Microsoft Office软件. ...
- linux服务器时间同步
date命令: date :查看当前时间,结果如下:Tue Mar 4 01:36:45 CST 2014 date -s 09:38:40 :设置当前时间,结果如下:Tue Mar 4 09:38: ...
- Linux下安装软件的错误
1. make configure GEN configure/bin/sh: 1: autoconf: not foundmake: *** [configure] Error 127 解决:sud ...