您的位置:首页 > 其它

POJ 2194 2850 计算几何

2018-07-30 23:26 267 查看

题意:

给你了n个圆,让你摞起来,问顶层圆心的坐标

(数据保证间隔两层的圆不会挨着)

思路:

按照题意模拟。

假设我们已经知道了一层两个相邻圆的坐标a:(x1,y1)和b:(x2,y2)

很容易求出来边长是2,2,dis(a,b)的三角形的面积

进而求出来底面所对应的高

找到底面中点

讲a->b 向量旋转90度  乘上高度

就搞出来了坐标

//By SiriusRen
#include <cmath>
#include <cstdio>
#include <algorithm>
using namespace std;
int cases,n;
typedef double db;
struct P{db x,y;P(){}P(db X,db Y){x=X,y=Y;}}p[15][15];
bool operator<(P a,P b){return a.x<b.x;}
P operator-(P a,P b){return P(a.x-b.x,a.y-b.y);}
P operator+(P a,P b){return P(a.x+b.x,a.y+b.y);}
db dis(P a){return sqrt(a.x*a.x+a.y*a.y);}
P get(P a,P b){
P c=b-a;db d=dis(c),p=d/2+2,S=sqrt(p*(p-2)*(p-2)*(p-d)),h=S/d*2;
c.x/=d,c.y/=d;c=P(-c.y*h,c.x*h);
return P((a.x+b.x)/2+c.x,(a.y+b.y)/2+c.y);
}
int main(){
while(scanf("%d",&n)&&n){
for(int i=1;i<=n;i++)scanf("%lf",&p
[i].x),p
[i].y=1;
sort(p
+1,p
+1+n);
for(int i=n-1;i;i--)
for(int j=1;j<=i;j++)
p[i][j]=get(p[i+1][j],p[i+1][j+1]);
printf("%.4lf %.4lf\n",p[1][1].x,p[1][1].y);
}
}

 

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: