Bounding box POJ
来源:互联网 发布:淘宝网懒人桌 编辑:程序博客网 时间:2024/05/17 11:59
Bounding box 题目链接
题意:给你一个正n边形的三个点,让你求出能够包含这个多边形所有点的矩形的最小面积,矩形平行于坐标轴。
思路: 首先通过三点确定多边形的外接圆心,然后用到向量旋转公式,求出多边形的每个点,找到最大和最小的坐标
然后算出面积。
公式我也不知道怎么推 ,记一下模板吧: x' ,y' 已知的某一点, x0 ,y0 外接圆心。
#include<cstdio>#include<iostream>#include<cmath>using namespace std;const double pi=acos(-1);struct Node{ double x,y;}a1,b1,c1;int n;Node calu(Node a,Node b,Node c){ Node ret; ret.x = ((b.y-c.y) * (pow(a.x,2)-pow(b.x,2)+pow(a.y,2)-pow(b.y,2)) - (a.y-b.y) * (pow(b.x,2)-pow(c.x,2)+pow(b.y,2)-pow(c.y,2))) / ((a.x-b.x)*(b.y-c.y)-(b.x-c.x)*(a.y-b.y)) / 2; ret.y = -(a.x-b.x) / (a.y-b.y) * (ret.x - (a.x+b.x)/2) + (a.y+b.y) / 2; return ret;}double solve(Node a,Node d){ double r=2*pi/n; double mxx,mnx,mxy,mny; mxx=mnx=a.x,mxy=mny=a.y; for(int i=0;i<n;i++) { double mx=(a.x-d.x)*cos(r*i)-(a.y-d.y)*sin(r*i)+d.x; double my=(a.x-d.x)*sin(r*i)-(a.y-d.y)*cos(r*i)+d.y; mxx=max(mx,mxx); mnx=min(mnx,mx); mxy=max(mxy,my); mny=min(mny,my); } return (mxx-mnx)*(mxy-mny);}int main(){ int kase=1; while(scanf("%d",&n)&&n) { scanf("%lf%lf%lf%lf%lf%lf",&a1.x,&a1.y,&b1.x,&b1.y,&c1.x,&c1.y); Node d=calu(a1,b1,c1); printf("Polygon %d: %.3f\n",kase++,solve(a1,d)); } return 0;}
模板 由三个点求外接圆面积:
Node calu(Node a,Node b,Node c){ Node ret; ret.x = ((b.y-c.y) * (pow(a.x,2)-pow(b.x,2)+pow(a.y,2)-pow(b.y,2)) - (a.y-b.y) * (pow(b.x,2)-pow(c.x,2)+pow(b.y,2)-pow(c.y,2))) / ((a.x-b.x)*(b.y-c.y)-(b.x-c.x)*(a.y-b.y)) / 2; ret.y = -(a.x-b.x) / (a.y-b.y) * (ret.x - (a.x+b.x)/2) + (a.y+b.y) / 2; return ret;}
模板 由外接圆求正 n 边形 的每个顶点。
double solve(Node a,Node d){ double r=2*pi/n; double mxx,mnx,mxy,mny; mxx=mnx=a.x,mxy=mny=a.y; for(int i=0;i<n;i++) { double mx=(a.x-d.x)*cos(r*i)-(a.y-d.y)*sin(r*i)+d.x; double my=(a.x-d.x)*sin(r*i)-(a.y-d.y)*cos(r*i)+d.y; mxx=max(mx,mxx); mnx=min(mnx,mx); mxy=max(mxy,my); mny=min(mny,my); } return (mxx-mnx)*(mxy-mny);}
阅读全文
0 0
- poj 2504 Bounding box
- Bounding box POJ
- POJ 2504 Bounding box 笔记
- zoj 1892 || poj 2504 || UVA 10577 Bounding box
- UVa 10577 - Bounding box
- POJ2504 Bounding box
- Bounding box regression详解
- Bounding Box label code
- bounding box overlap 计算
- Bounding box regression详解
- Bounding-box Regression
- Bounding box regression详解
- Single Bounding Box Regression
- 踩着坑画bounding-box
- Bounding box Regression详解
- bounding box regression
- Bounding-box Regression
- Bounding box 回归
- thinkphp3.2.3 事务
- [RK3288][Android7.1.2] Launcher3 源码阅读之step1:查看项目的目录并找到入口
- tf.mul()
- Git命令清单
- HashMap死循环问题
- Bounding box POJ
- 现在的鱼蛋佬...
- Android开源网站一网打尽
- JS中使用new Date(str)创建时间对象不兼容firefox和ie的解决方法(两种)
- Java线程-4:线程状态的转换
- Random类常用的方法实例
- hdu 1071 The area
- Jquery Ajax方法传值到action的方法
- android Handler机制 消息机制