zoj3806Incircle and Circumcircle
生活随笔
收集整理的這篇文章主要介紹了
zoj3806Incircle and Circumcircle
小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
鏈接
自己的本本沒有裝畫圖軟件,先借用兩張圖片。。博客園不讓貼源地址。。。
可以想到對(duì)于一個(gè)確定的外接圓的三角形來說內(nèi)切圓最大的時(shí)候?yàn)榈冗吶切?#xff0c;如下圖:
確定有合法的解之后,接下來就是去找這個(gè)解,解不唯一,可以知道一定可以構(gòu)造出一個(gè)等腰三角形使得滿足條件,可以看下圖,對(duì)于一個(gè)確定的外接圓,已知底邊和外接圓半徑的話,是可以求出三邊的,隨著底邊的縮小和伸長內(nèi)切圓是先變大后變小,而最大的時(shí)候就是上述所說,等邊的時(shí)候。所以知道了上下界,就可以直接二分底邊了,二分的區(qū)間就是下圖所標(biāo)區(qū)間。
1 #include <iostream> 2 #include<cstdio> 3 #include<cstring> 4 #include<algorithm> 5 #include<stdlib.h> 6 #include<vector> 7 #include<cmath> 8 #include<queue> 9 #include<set> 10 using namespace std; 11 #define N 100000 12 #define LL long long 13 #define INF 0xfffffff 14 const double eps = 1e-10; 15 const double pi = acos(-1.0); 16 const double inf = ~0u>>2; 17 int dcmp(double x) 18 { 19 if(fabs(x)<eps) return 0; 20 return x<0?-1:1; 21 } 22 int cal(double x,double R,double r) 23 { 24 if(dcmp(R*R-x*x)<0) return 0; 25 double a = sqrt(2*R*R+2*R*sqrt(R*R-x*x)); 26 double b = a; 27 double c = 2*x; 28 double s = (a+b+c)/2; 29 double tt = (s-a)*(s-b)*(s-c)/s; 30 if(dcmp(tt)<0) return 0; 31 double tr = sqrt(tt); 32 if(dcmp(tr-r)>=0) return 1; 33 return 0; 34 } 35 int main() 36 { 37 double r1,r2; 38 while(scanf("%lf%lf",&r1,&r2)!=EOF) 39 { 40 if(dcmp(2*r1-r2)>0) 41 { 42 puts("NO Solution!"); 43 continue; 44 } 45 double rig = sqrt(3.0)*r2,lef = 0,mid; 46 while(rig-lef>eps) 47 { 48 mid = (lef+rig)/2; 49 if(cal(mid,r2,r1)) 50 rig = mid; 51 else lef = mid; 52 } 53 // printf("%f\n",rig); 54 double a = sqrt(2*r2*r2+2*r2*sqrt(r2*r2-rig*rig)); 55 double b = a; 56 double c = 2*rig; 57 printf("%.15f %.15f %.15f\n",a,b,c); 58 } 59 return 0; 60 } View Code?
轉(zhuǎn)載于:https://www.cnblogs.com/shangyu/p/3963928.html
總結(jié)
以上是生活随笔為你收集整理的zoj3806Incircle and Circumcircle的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: c++能过,g++过不了
- 下一篇: Jmeter(三)_配置元件