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,现在要使飞机与空间站相遇,飞机的速度是 ...
随机推荐
- Android应用开发学习之Toast消息提示框
作者:刘昊昱 博客:http://blog.csdn.net/liuhaoyutz 本文我们来看Toast消息提示框的用法.使用Toast消息提示框一般有三个步骤: 1. 创建一个Toast对象.可 ...
- hiberbate的工作原理
hibernate 简介:hibernate是一个开源框架,它是对象关联关系映射的框架,它对JDBC做了轻量级的封装,而我们java程序员可以使用面向对象的思想来操纵数据库.hibernate核心接口 ...
- 创建一个jQuery UI的垂直进度条效果
日期:2013-9-24 来源:GBin1.com 在线演示 缺省的jQuery UI只有水平的进度条效果,没有垂直的进度条效果,仅仅重新定义JQuery UI的CSS不能解决这个问题. 这里我们扩 ...
- 关于c语言的一个小bug(c专家编程)
不多说,说了都是累赘!直接看代码吧! #include <stdio.h> int array[] = {23, 34, 12, 17, 204, 99, 16}; #define TOT ...
- 涂抹Oracle笔记1-创建数据库及配置监听程序
一.安装ORACLE数据库软件及创建实例OLTP:online transaction processing 指那些短事务,高并发,读写频繁的数据库系统.--DB_BLOCK_SIZE通常设置较小.O ...
- MATLAB快速注释方法
觉得有用,未免以后忘记,收藏了.原文来自:http://i.azpala.com/2008/09/18/matlab-multi-line-comment/ A. %{ 若干语句 %} B. 多行注释 ...
- 如何利用自己的电脑做服务器发布tomcat的WEB项目供外网访问
1.首先你要确定你有一个外网ip地址.如果你分配到的是一个局域网IP地址需要经过一系列的转换为外网ip地址,然后继续下面操作. 2.拿到外网IP地址,进行tomcat的server.xml文件的配置. ...
- ajax用户名校验demo详解
//用户名校验的方法 //这个方法使用XMLHTTPRequest对象进行AJAX的异步数据交互 var xmlhttp; function verify(){ //1.使用dom的方式获取文本框中的 ...
- rub、sass和compass的安装
长话短说,直接进入正题. [ruby安装] ruby下载网址:http://rubyinstaller.org/downloads/ 选择适合自己电脑的版本: 下载完成后直接双击安装,记得勾选加入环境 ...
- SQL基础-->层次化查询(START BY ... CONNECT BY PRIOR)[转]
--====================================================== --SQL基础-->层次化查询(START BY ... CONNECT BY ...