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;}
相关文章推荐
- JAVA中double类型计算精度控制
- [POJ2318]TOYS(计算几何-叉积+二分)
- HDU Strange fuction(二分+精度控制)
- Codeforces Round #365 (Div. 2) C. Chris and Road(计算几何+二分)
- [HDU 4741]Save Labman No.004[计算几何][精度]
- POJ 3575(计算几何与二分-无尽的小数处理)
- SGU 124. Broken line 射线法 eps的精准运用,计算几何 难度:3
- Codeforces 8D Two Friends 三分+二分+计算几何
- HDU—2899—strange fuction—【二分】【精度控制】
- ZOJ 3913 Bob wants to pour water (计算几何+二分)
- HDU 2899 Strange fuction 二分 + 精度控制
- POJ 2318 TOYS 计算几何 入门题 叉积 + 二分
- 计算几何-二分求幂
- HDU 4766 Network(计算几何 二分+三分)
- [SCOI 2015集训-2015.4.16]Problem B(计算几何+极角序二分)
- POJ 2318 TOYS 计算几何 入门题 叉积 + 二分
- POJ-1905-Expanding Rods【二分】【计算几何】
- 【算法学习笔记】52.一道题的三种方法..二分答案、动态规划、计算几何 SJTU OJ 1250 BestSubsequence
- 计算几何 [二分答案]
- (二分,精度控制)Can you solve this equation?--HDOJ