ZOJ 3147 Dezider's Coverup【最小圆覆盖】【模板题】
来源:互联网 发布:java 心跳实现 编辑:程序博客网 时间:2024/05/17 06:16
Zlatica to his house for dinner. The trouble is, he tripped with the sauce in his hands (thankfully this was in the morning and Zlatica did not see it) and many bright red droplets fell on his white carpet. Now Dezider is starting to panic because he wants to have a perfectly clean house to impress Zlatica. Fortunately, there is a store nearby which sells all sizes of (expensive) circular rugs. Dezider does not have much money so he wants to buy the smallest rug with an integer radius which will cover all the droplets. You need to write a program to help him determine the right size to buy.
Input
Each test cases starts with one positive integer n, the number of droplets on the carpet. Each of the following n lines contains two floating-point numbers, separated by white space, which represent the x- and y-coordinate of the corresponding droplet.
Output
One line for each test case which consists of a single integer, the radius of the smallest circular rug needed to cover all the droplets.
Sample Input
41 -0.51.5 00.5 0.51 0.5
Sample Output
1
because a circular rug of radius 1 and center for example at 1,0 will cover the four droplets described by the input.
#include <stdio.h>#include <math.h>const int maxn=1005;const double eps=1e-9;struct point{ double x, y; point operator-(point & tp) { point rp; rp.x=x-tp.x; rp.y=y-tp.y; return rp; }}p[maxn];struct circle{ double r; point centre;}c;struct tripoint{ point t[3];};double dis(point a, point b){ a=a-b; return sqrt(a.x * a.x + a.y * a.y);}double triangleArea(tripoint t){ point p1, p2; p1=t.t[1]-t.t[0]; p2=t.t[2]-t.t[0]; return fabs(p1.x*p2.y-p1.y*p2.x)/2;}circle circumcircleOfTriangle(tripoint t){ //三角形的外接圆 circle tmp; double a, b, c, c1, c2; double xA, yA, xB, yB, xC, yC; a=dis(t.t[0], t.t[1]); b=dis(t.t[1], t.t[2]); c=dis(t.t[2], t.t[0]); //根据S = a * b * c / R / 4;求半径R tmp.r=a*b*c/triangleArea(t)/4; xA=t.t[0].x; yA=t.t[0].y; xB=t.t[1].x; yB=t.t[1].y; xC=t.t[2].x; yC=t.t[2].y; c1=(xA*xA+yA*yA-xB*xB-yB*yB)/2; c2=(xA*xA+yA*yA-xC*xC-yC*yC)/2; tmp.centre.x=(c1*(yA-yC)-c2*(yA-yB))/((xA-xB)*(yA-yC)-(xA-xC)*(yA-yB)); tmp.centre.y=(c1*(xA-xC)-c2*(xA-xB))/((yA-yB)*(xA-xC)-(yA-yC)*(xA-xB)); return tmp;}circle MinCircle2(int tce, tripoint ce){ circle tmp; if(tce==0) tmp.r=-2; else if(tce==1) { tmp.centre=ce.t[0]; tmp.r=0; } else if(tce==2) { tmp.r=dis(ce.t[0], ce.t[1])/2; tmp.centre.x=(ce.t[0].x+ce.t[1].x)/2; tmp.centre.y=(ce.t[0].y+ce.t[1].y)/2; } else if(tce==3) tmp=circumcircleOfTriangle(ce); return tmp;}void MinCircle(int t, int tce, tripoint ce){ int i, j; point tmp; c=MinCircle2(tce, ce); if(tce==3) return; for(i=1; i<=t; i++) { if(dis(p[i], c.centre)>c.r) { ce.t[tce]=p[i]; MinCircle(i-1, tce+1, ce); tmp=p[i]; for(j=i; j>=2; j--) p[j]=p[j-1]; p[1]=tmp; } }}int main(){ int n,i; while(~scanf("%d", &n) && n) { for(i=1; i<=n; i++) scanf("%lf%lf", &p[i].x, &p[i].y); tripoint ce; MinCircle(n, 0, ce); int x=(int)c.r; if(c.r-x<eps) { printf("%d\n",x); } else printf("%d\n",x+1); } return 0;}
- ZOJ 3147 Dezider's Coverup【最小圆覆盖】【模板题】
- 最小圆覆盖——模板题
- 最小圆覆盖模板(zoj1450)
- ZOJ 1450 Minimal Circle 最小圆覆盖
- ZOJ 1450 HDU 3007 (最小圆覆盖)
- ZOJ 1450 Minimal Circle 点集的最小圆覆盖
- ZOJ 1450 Minimal Circle 点集的最小圆覆盖
- 最小圆覆盖
- 最小圆覆盖
- 最小圆覆盖
- 最小圆覆盖
- 最小圆覆盖
- 最小圆覆盖
- 最小圆覆盖问题
- 最小圆覆盖
- 最小圆覆盖
- 最小圆覆盖算法
- 最小圆覆盖问题
- SpringMVC文件上传拦截器,大小验证,类型验证
- lambda函数,匿名函数
- ISO C90 forbids mixed declarations and code
- Java开发天气预报系统
- iOS 网络实时监控
- ZOJ 3147 Dezider's Coverup【最小圆覆盖】【模板题】
- SpringMVC之框架概述
- Go语言入门教程(二)运行单个文件
- c++全套视频分享
- [题解]bzoj1691 Usaco2007Dec 挑剔的美食家
- Maven Project和 Maven Module的区别
- 对象,类,属性,成员变量,局部变量
- 利用socket进行服务端与客户端传文件
- xib写好约束后 代码动态修改约束