POJ3525+半平面交
来源:互联网 发布:中国有多强大 知乎 编辑:程序博客网 时间:2024/04/30 13:06
题意:求出给定的凸多边形的内接圆
#include<stdio.h>#include<string.h>#include<stdlib.h>#include<math.h>#include<algorithm>using namespace std;const int maxn = 155;const int maxm = 1005;const double Min = 0.0;const double Max = 10000000000.0;const double eps = 1e-8;const double pi = acos(-1.0);struct Point{double x,y;};struct Line{Point a,b;};Point pnt[ maxn ],res[ maxm ],tp[ maxm ];double xmult( Point op,Point sp,Point ep ){return (sp.x-op.x)*(ep.y-op.y)-(sp.y-op.y)*(ep.x-op.x);}double dist( Point a,Point b ){return sqrt( (a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y) );}void Get_equation( Point p1,Point p2,double &a,double &b,double &c ){a = p2.y-p1.y;b = p1.x-p2.x;c = p2.x*p1.y-p1.x*p2.y;}//直线Point Intersection( Point p1,Point p2,double a,double b,double c ){double u = fabs( a*p1.x+b*p1.y+c );double v = fabs( a*p2.x+b*p2.y+c );Point tt;tt.x = (p1.x*v+p2.x*u)/(u+v);tt.y = (p1.y*v+p2.y*u)/(u+v);return tt;}//交点double GetArea( Point p[],int n ){double sum = 0;for( int i=2;i<n;i++ ){sum += xmult( p[1],p[i],p[i+1] );}return -sum/2.0;}//面积void cut( double a,double b,double c,int &cnt ){int temp = 0;for( int i=1;i<=cnt;i++ ){if( a*res[i].x+b*res[i].y+c>-eps ){//>=0tp[ ++temp ] = res[i];}else{if( a*res[i-1].x+b*res[i-1].y+c>eps ){tp[ ++temp ] = Intersection( res[i-1],res[i],a,b,c );}if( a*res[i+1].x+b*res[i+1].y+c>eps ){tp[ ++temp ] = Intersection( res[i],res[i+1],a,b,c );}}}for( int i=1;i<=temp;i++ )res[i] = tp[i];res[ 0 ] = res[ temp ];res[ temp+1 ] = res[ 1 ];cnt = temp;}bool solve( int n,double r ){for( int i=0;i<=n+1;i++ )res[ i ] = pnt[ i ];int cnt = n;for(int i=1;i<=n;i++){ double a,b,c; Point p1,p2,p3; p1.y=pnt[i].x-pnt[i+1].x;p1.x=pnt[i+1].y-pnt[i].y; double k=r/sqrt(p1.x*p1.x+p1.y*p1.y); p1.x=k*p1.x;p1.y=p1.y*k; p2.x=p1.x+pnt[i].x;p2.y=p1.y+pnt[i].y; p3.x=p1.x+pnt[i+1].x;p3.y=p1.y+pnt[i+1].y; Get_equation( p2,p3,a,b,c ); cut(a,b,c,cnt); } if( cnt<=1 ) return false;else return true;}int main(){int n;while( scanf("%d",&n)==1,n ){for( int i=1;i<=n;i++ )scanf("%lf%lf",&pnt[i].x,&pnt[i].y);if( GetArea( pnt,n)<eps )reverse( pnt+1,pnt+1+n );pnt[0] = pnt[n];pnt[n+1] = pnt[1];double L,R,mid,ans;L = Min;R = Max;while( R-L>=eps ){//R>Lmid = (L+R)/2.0;if( solve( n,mid )==true ){ans = mid;L = mid;}else{R = mid;}}printf("%.6lf\n",ans);}return 0;}
- POJ3525+半平面交
- poj3525 二分+半平面交
- POJ3525(二分+半平面交)
- POJ3525 Most Distant Point from the Sea(半平面交)
- UVAlive 3890&Poj3525 半平面交+二分 解题报告
- POJ3525-Most Distant Point from the Sea(二分+半平面交)
- [POJ3525]Most Distant Point from the Sea(二分+半平面交)
- POJ3525 Most Distant Point from the Sea 半平面交+二分答案+直线平移
- POJ3525/LA3890 Most Distant Point from the Sea 解题报告【计算几何】【二分答案】【半平面交】
- poj3525(二分+半平面判定)
- 例4.10 POJ3525/LA3890离海最远的点 半平面交 + 二分法 + double小数点后有效位数处理方式/printf与g++、c++的问题
- pku2451 半平面交
- 半平面交
- 半平面交
- poj2540 半平面交
- 半平面交
- poj2451 半平面交
- 半平面交.....
- H.264解码器中参考图像的管理
- Android 状态栏通知Notification、NotificationManager详解
- R语言基础-向量
- 删除list或vector中的自定义结构体对象
- log4j使用心得之二 -- log4j配置相对路径日志
- POJ3525+半平面交
- Linq本质论(1)
- openwrt mentohust tp-WR703
- 使用Java进行远程方法调用的几个方案及比较
- hdu 1247 Hat’s Words(字典树)
- R语言基础-矩阵和列表
- 轻松10步本地安装WordPress(图)
- Fortran使用隐形DO循环和reshape给一维和多维数组赋初值
- 将512字节写图片,后跟指令==调指令,必调图片==用方块儿或图片调指令。