您的位置:首页 > 其它

ZOJ3806 二分计算几何eps控制精度

2014-09-02 21:37 387 查看
Incircle and CircumcircleTime Limit: 2 Seconds     Memory Limit: 65536 KB      Special JudgeA triangle is one the basic shapes in geometry. It's a polygon with three vertices and three sides which are line segments. A triangle with verticesA, B, C is denoted ΔABC. And its three sides,BC, CA,AB are often denoteda, b and c.The incircle of a triangle is the largest circle contained in the triangle, it is tangent to the three sides. The center of the incircle is called the triangle's incenter and the radius of the incircle is called inradius, which is denotedr.The circumcircle of a triangle is the circle which passes through all its three vertices. The center of the this circle is called circumcenter and its radius is called circumradius, which is denotedR.It's very easy to calculate r and R after knowing a,b and c. Now you are given r and R, can you calculate a valid triple (a,b, c)?

Input

There are multiple cases. Each case has two positive integers r andR in one line. (r and R are less than 105)

Ouput

For each case, print three floating numbers a, b andc in one line if it's possible to get r and R. If there are no possible tuples, print "NO Solution!".The judge program uses your a, b and c to calculate the inradius and circumradius. Only the relative error of your inradius and circumradius less than 10-8 will be accepted.

Sample Input

1 2
2 5
9 9

Sample Ouput

3.464101615137754587 3.464101615137754587 3.464101615137754587
6 8 10
NO Solution!
调那俩eps调到蛋疼。。。
假设是等腰三角形二分三角形的高就好了,需要一些计算公式~写的挺蛋疼。。
#define DeBUG#include <iostream>#include <cstdio>#include <cstring>#include <cmath>#include <cstdlib>#include <algorithm>#include <vector>#include <stack>#include <queue>#include <string>#include <set>#include <sstream>#include <map>#include <list>#include <bitset>using namespace std ;#define zero {0}#define INF 0x3f3f3f3f#define EPS 1e-8#define TRUE true#define FALSE falsetypedef long long LL;const double PI = acos(-1.0);//#pragma comment(linker, "/STACK:102400000,102400000")inline int sgn(double x){return fabs(x) < EPS ? 0 : (x < 0 ? -1 : 1);}#define N 100005double R, rr;double geta(double c){double x = sqrt(R * R - c * c / 4.0);double a = sqrt((R - x) * (R - x) + c * c / 4.0);return a;// return sqrt((R - sqrt(R * R - c * c / 4.0)) * (R - sqrt(R * R - c * c / 4.0)) + c * c / 4.0);}double getadown(double c){double x = sqrt(R * R - c * c / 4.0);double a = sqrt((R + x) * (R + x) + c * c / 4.0);return a;}double getr(double c){double a = geta(c);return (2.0 * R * a * c - R * c * c) / (2.0 * a * a);}double getr2(double c){double a = getadown(c);return (2.0 * R * a * c - R * c * c) / (2.0 * a * a);}int main(){#ifdef DeBUGsfreopen("C:\\Users\\Sky\\Desktop\\1.in", "r", stdin);#endifconst double epsget = 1e-13;while (scanf("%lf%lf", &rr, &R) + 1){if (sgn(2 * rr - R) > 0){printf("NO Solution!\n");}else{double l = 0.0;double r = R * 2;double mid;double nowr;int flag = 0;while (sgn(l-r) < 0){// cout << "1" << flag << endl;mid = (l + r) / 2.0;nowr = getr(mid);if (sgn( nowr - rr) < 0)l = mid + epsget;else if (sgn( nowr - rr) > 0)r = mid - epsget;else{flag = 1;break;}}if (!flag){l = sqrt(3) * R;r = 2 * R;while (sgn(l-r) < 0){// cout << "2" << flag << endl;mid = (l + r) / 2.0;nowr = getr2(mid);if (sgn( nowr - rr) > 0)l = mid + epsget;else if (sgn(nowr - rr) < 0)r = mid - epsget;else{flag = 2;break;}}}// 3.464101615137754587if (flag == 1){printf("%.20lf %.20lf %.20lf\n", geta(mid), geta(mid), mid);}else if (flag == 2){printf("%.20lf %.20lf %.20lf\n", getadown(mid), getadown(mid), mid);}else{printf("NO Solution!\n");}}}return 0;}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: