UVA LIVE-4642 - Malfatti Circles

给出三角形三个顶点,求出三个互切的圆的半径
尽管大白鼠说能够推出公式,但是这个公式仅仅怕没那么easy推……我左看右看上看下看也推不出。
应该是要做辅助线什么的,那也……
因为非常easy就推出了关于三个半径的三元方程组,那么就试试搜索吧,搜当中随意一个半径,仅仅要满足这个方程组就能够了,
那么就二分搜索吧,当然,这个单调性呢?
看图可知,例如说,我们搜最靠近最上面的顶点的圆的半径r1,由于,以下两圆的r2,r3都是由r1推出,由于方程组的约束作用,那么以下两个圆肯定跟最上面的圆相切,当然也肯定跟三角形的边相切,可是这两个圆之间可不一定相切了,假设r1太大,那么这两个圆肯定相离,由它们两推出的底边肯定就小了,假设r1太小,那么这两个圆肯定相交,由它们两推出的底边肯定就大了。好的,有单调性,也就是说,r1跟底边长度是单调递减的关系。
r1的下界就是0,上界却不能太大,由于太大,r2,r3就木有了,就是说方程组是无法通过r1推出满足的r2,r3的,带到方程组里是会出问题的,所以,r1不能太大,那么多大合适呢?列出方程组就非常easy知道了。
这是大白鼠的计算几何Basic部分的最后一题,那么这个部分就圆满结束了。通过这个部分,解析几何的能力有所提升。
我的代码:
#include<iostream>
#include<map>
#include<string>
#include<cstring>
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<queue>
#include<vector>
#include<algorithm>
using namespace std;
const double eps=1e-7;
struct dot
{
double x,y;
dot(){}
dot(double a,double b){x=a;y=b;}
dot operator -(const dot &a){return dot(x-a.x,y-a.y);}
double mod(){return sqrt(pow(x,2)+pow(y,2));}
double dis(const dot &a) {return sqrt(pow(x-a.x,2)+pow(y-a.y,2));}
double mul(const dot &a) {return x*a.x+y*a.y;}
};
int main()
{
bool flag;
int i,j;
dot a[3],c[3];
double l,h,m,b[3],e[3],r[3],A,B,C;
while(1)
{
flag=1;
for(i=0;i<3;i++)
{
cin>>a[i].x>>a[i].y;
if(a[i].x!=0||a[i].y!=0)
flag=0;
}
if(flag)
break;
for(i=0;i<3;i++)
{
c[0]=a[(i+1)%3]-a[i];
c[1]=a[(i+2)%3]-a[i];
b[i]=acos(c[0].mul(c[1])/c[0].mod()/c[1].mod())/2;
}
e[0]=a[0].dis(a[1]);
e[1]=a[1].dis(a[2]);
e[2]=a[0].dis(a[2]);
l=0;
h=min(e[0]*tan(b[0]),e[2]*tan(b[0]));
while(h-l>eps)
{
m=(l+h)/2;
A=1/tan(b[1]);B=2*sqrt(m);C=m/tan(b[0])-e[0];
r[0]=(sqrt(B*B-4*A*C)-B)/A/2;
A=1/tan(b[2]);B=2*sqrt(m);C=m/tan(b[0])-e[2];
r[1]=(sqrt(B*B-4*A*C)-B)/A/2;
r[0]*=r[0];
r[1]*=r[1];
if(r[0]/tan(b[1])+r[1]/tan(b[2])+2*sqrt(r[0]*r[1])-e[1]>0)
l=m;
else
h=m;
}
printf("%.6lf %.6lf %.6lf\n",l,r[0],r[1]);
}
}
原题:
Time limit: 3.000 seconds
- the circle with the center (25.629089, -10.057956) and the radius 9.942044,
- the circle with the center (53.225883, -0.849435) and the radius 19.150565, and
- the circle with the center (19.701191, 19.203466) and the radius 19.913790.
Your mission is to write a program to calculate the radii of the Malfatti circles of the given triangles.

Input
The input is a sequence of datasets. A dataset is a line containing six integers
x1, y1,
x2, y2,
x3 and y3 in this order, separated by a space. The coordinates of the vertices of the given triangle are (x1,
y1), (x2,
y2) and (x3,
y3), respectively. You can assume that the vertices form a triangle counterclockwise. You can also assume that the following two conditions hold.
- All of the coordinate values are greater than -1000 and less than 1000.
- None of the Malfatti circles of the triangle has a radius less than 0.1.
The end of the input is indicated by a line containing six zeros separated by a space.
Output
For each input dataset, three decimal fractions r1,
r2 and r3 should be printed in a line in this order separated by a space. The radii of the Malfatti circles nearest to the vertices with the coordinates
(x1, y1),
(x2, y2) and (x3,
y3) should be r1,
r2 and r3, respectively.
None of the output values may have an error greater than 0.0001. No extra character should appear in the output.
Sample Input
20 80 -40 -20 120 -20
20 -20 120 -20 -40 80
0 0 1 0 0 1
0 0 999 1 -999 1
897 -916 847 -972 890 -925
999 999 -999 -998 -998 -999
-999 -999 999 -999 0 731
-999 -999 999 -464 -464 999
979 -436 -955 -337 157 -439
0 0 0 0 0 0
Sample Output
21.565935 24.409005 27.107493
9.942044 19.150565 19.913790
0.148847 0.207107 0.207107
0.125125 0.499750 0.499750
0.373458 0.383897 0.100456
0.706768 0.353509 0.353509
365.638023 365.638023 365.601038
378.524085 378.605339 378.605339
21.895803 22.052921 5.895714
UVA LIVE-4642 - Malfatti Circles的更多相关文章
- 【UVALive 4642】Malfatti Circles(圆,二分)
题 给定三角形,求三个两两相切且与三角形的一条边相切的圆的半径. 二分一个半径,可以得出另外两个半径,需要推一推公式(太久了,我忘记了) #include<cstdio> #include ...
- UVa 247 (传递闭包) Calling Circles
题意: 有n个人m通电话,如果有两个人相互打电话(直接或间接)则在同一个电话圈里.输出所有电话圈的人的名单. 分析: 根据打电话的关系,可以建一个有向图,然后用Warshall算法求传递闭包. 最后输 ...
- 【uva 247】Calling Circles(图论--Floyd 传递闭包+并查集 连通分量)
题意:有N个人互相打了M次电话,请找出所有电话圈(Eg.a→b,b→c,c→d,d→a 就算一个电话圈)并输出.(N≤25,L≤25,注意输出格式) 解法:由于N比较小所有n^2或n^3的复杂度都没有 ...
- UVa 247 - Calling Circles(Floyd求有向图的传递闭包)
链接: https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem& ...
- UVa 247 Calling Circles【传递闭包】
题意:给出n个人的m次电话,问最后构成多少个环,找出所有的环 自己想的是:用map来储存人名,每个人名映射成一个数字编号,再用并查集,求出有多少块连通块,输出 可是map不熟,写不出来,而且用并查集输 ...
- UVA - 247 Calling Circles Floyd判圈
思路:利用的Floyd判圈,如果i能到j,j也能到i说明i和j在同一个圈里.每个人的名字可用map编号.最后DFS打印答案即可. AC代码 #include <cstdio> #inclu ...
- Calling Circles(UVa 247)(Floyd 算法)
用Floyd算法求出传递闭包,然后用dfs求出每条连通分量.注意其中用到的几个小技巧: #include<cstdio> #include<iostream> #include ...
- UVa 247 Calling Circles (DFS+Floyd)
题意:如果两个人互通电话,那么他们就在一个电话圈里,现在给定 n 个人,并且给定 m 个通话记录,让你输出所有的电话圈. 析:刚开始没想到是Floyd算法,后来才知道是这个算法,利用这个算法进行连通性 ...
- UVA 247 - Calling Circles (Floyd)
互相可以打电话是一个传递关系,所以Floyd求传递封包,dfs找一个尽量大的圈. #include<bits/stdc++.h> using namespace std; ; map< ...
随机推荐
- [SDOI2009][bzoj1877] 晨跑 [费用流]
题面: 传送门 思路: 一个点只能走一回,路径不能相交...... 显然可以转化为网络流的决策来做 我们构建一个网络,令其最大流等于最大的跑步天数即可 怎么构造呢? 对于每个点只能走一次的限制,可以考 ...
- linux系统初始化——busybox的inittab文件格式说明
busybox的inittab文件格式说明 要写自己的inittab,需要理解busybox的inittab文件格式. busybox的inittab文件与通常的inittab不同,它没有runlev ...
- react 基础语法复习1- 搭建开发环境
之前有看过阮一峰老师的react教程跟着做了一遍,学习了一下.好久没看,有点忘记了,这次跟着脚手架工具系统的复习一遍.顺便学习学习 react-router 和 redux 首先,脚手架工具我使用的是 ...
- Docker分层原理与内部结构
转自:1 : https://www.csdn.net/article/2015-08-21/2825511 2: http://blog.51cto.com/wzlinux/2044797 ...
- BZOJ 4766: 文艺计算姬
4766: 文艺计算姬 Time Limit: 1 Sec Memory Limit: 128 MBSubmit: 456 Solved: 239[Submit][Status][Discuss] ...
- java网络编程学习笔记(二):socket详解
1.Socket有多种构造方法,大多数构造方法在构造的时候就指定了连接的主机和端口号.当客户端的构造方法与服务器连接的时候,可能需要等待一段时间,因为需要建立连接.默认情况下,Socket的构造方法会 ...
- android基本控件学习-----Date&Time
Date&Time这里一共讲解下面6个: TextClock(文本时钟),AnalogClock(模拟时钟),Chronometer(计时器),DatePicker(日期选择器),TimePi ...
- netbeans8.2下struts2的Java Web开发Demo1
struts2框架主要是封装了servlet,简化了jsp跳转的复杂操作,并且提供了易于编写的标签,可以快速开发view层的代码. 过去,我们用jsp和servlet搭配,实现展现时,大体的过程是: ...
- hdu 5059(模拟)
Help him Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Su ...
- 二叉树遍历 Morris
二叉树的遍历,先根遍历,不适用递归,存储空间为 O(1) 转自:http://chuansongme.com/n/100461 MorrisInOrder(): while 没有结束 如果当前节点没有 ...