栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

zoj 1892 Bounding Box

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

zoj 1892 Bounding Box

#include <queue>#include <stack>#include <math.h>#include <stdio.h>#include <stdlib.h>#include <iostream>#include <limits.h>#include <string.h>#include <string>#include <algorithm>using namespace std;struct point{double x,y;};const double inf = 1e20;const double pi = acos(-1.0);point p[3];const double eps = 1e-10; bool dy(double x,double y){return x > y + eps;}// x > y bool xy(double x,double y){return x < y - eps;}// x < y bool dyd(double x,double y){ return x > y - eps;}// x >= y bool xyd(double x,double y){return x < y + eps;} // x <= y bool dd(double x,double y) {return fabs( x - y ) < eps;}  // x == ypoint l2l_inst_p(point u1,point u2,point v1,point v2){point ans = u1;double t = ((u1.x - v1.x)*(v1.y - v2.y) - (u1.y - v1.y)*(v1.x - v2.x))/((u1.x - u2.x)*(v1.y - v2.y) - (u1.y - u2.y)*(v1.x - v2.x));ans.x += (u2.x - u1.x)*t;ans.y += (u2.y - u1.y)*t;return ans;}point circumcenter(point a,point b,point c){point ua,ub,va,vb;ua.x = ( a.x + b.x )/2;ua.y = ( a.y + b.y )/2;ub.x = ua.x - a.y + b.y; ub.y = ua.y + a.x - b.x;va.x = ( a.x + c.x )/2;va.y = ( a.y + c.y )/2;vb.x = va.x - a.y + c.y;vb.y = va.y + a.x - c.x;return l2l_inst_p(ua,ub,va,vb);} point Whirl(double cosl, double sinl, point a, point b){b.x -= a.x; b.y -= a.y;       point c;       c.x = b.x * cosl - b.y * sinl + a.x;       c.y = b.x * sinl + b.y * cosl + a.y;       return c;}int main(){int n,ind = 1;double minx,miny,maxx,maxy;while( ~scanf("%d",&n) && n ){minx = miny = inf; maxx = maxy = -inf;for(int i=0; i<3; i++)scanf("%lf%lf",&p[i].x,&p[i].y);point c = circumcenter(p[0],p[1],p[2]);point s = p[0],k;double a = 2*pi/n;for(int i=0; i<n; i++){k = Whirl(cos(i*a),sin(i*a),c,s);if( xy(k.x,minx) ) minx = k.x;if( xy(k.y,miny) ) miny = k.y;if( dy(k.x,maxx) ) maxx = k.x;if( dy(k.y,maxy) ) maxy = k.y;}double ans = (maxx - minx)*(maxy - miny);printf("Polygon %d: %.3lfn",ind++,ans);}return 0;}
转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/367651.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号