Formula

[提交] [状态] [讨论版] [命题人:admin]

题目描述

Tim is quite a bookworm. Each Saturday he goes to the local library and spends the whole day reading old books. He is mostly interested in ancient history, but from time to time he also reads scientific books. Last weekend he found a series of books called “The Elements” written by some old Greek called Euclid. Tim had never heard of him. All 12 books were filled with definitions, propositions and proofs concerning elementary geometry.
Tim read all books very carefully, but one handwritten note just stuck in his mind. Someone wrote just after Book 4, Proposition 4:
Using Heron’s formula, one can easily derive that the following formula holds for a triangle with incircle radius r, area A, and lengths a, b, c of the three sides.

Since Tim is not a very trusting person, he doesn’t believe that this formula is correct. However,Tim remembers from school that Heron’s formula states a relationship between the area of a triangle and the lengths of its three sides. And of course he trusts this formula. After all, we can
trust teachers, right?


inscribed their incircles and measured their radius. Now he wants to check the formula against his measurements, but he is already quite tired from constructing all those triangles on paper.
He asks you to write a program that, given the coordinates of the triangle’s vertices, computes the incircle radius according to the formula he found in the book and outputs the difference to the value he measured in percent.

 

输入

The input consists of:
• three lines, the i-th of them with two integers x i and y i ( − 103 ≤ x i , y i ≤ 103 for all 1 ≤ i ≤ 3), where (x i , y i ) are the coordinates of one of the triangle’s vertices;
• one line with one real number r (0.1 ≤ r ≤ 106 ), where r is the incircle radius that Tim measured when he constructed the triangle on paper.
The three coordinates will never be collinear. The triangle’s area will always be greater or equal to 0.1.

 

输出

Output the difference between the measured incircle radius and the radius computed according to the formula as a percentage value, where the measured radius corresponds to 100%. The output is positive if the computed radius is larger than the measured one, 0 if they are equal, or
negative otherwise. The output must be accurate to an absolute or relative error of at most 10-3 .

 

样例输入

0 0
10 0
0 10
5.0

 

样例输出

-41.421

题意:输入中给定预先的三角形内接圆的半径 r , 已知三角形三个点的坐标,a,b,c代表三角形的三条边的大小

然后使用求出三角形的面积,再根据求出真实的

三角形的内接圆的半径大小,再求出偏差的百分比即可

代码:

#include<stdio.h>
#include<string.h>
#include<algorithm>
#include<math.h>
using namespace std;
#define ll long long int
double maze[5][3];
double panduan(int x,int y)
{
	return sqrt((maze[x][0]-maze[y][0])*(maze[x][0]-maze[y][0])+(maze[x][1]-maze[y][1])*(maze[x][1]-maze[y][1]));
}
int main()
{
	for(int i=0;i<3;i++)
		scanf("%lf %lf",&maze[i][0],&maze[i][1]);
	double r;
	scanf("%lf",&r);
	double u,v,w;
	u=panduan(0,1);
	v=panduan(1,2);
	w=panduan(0,2);
	double A;
	A=sqrt(4*u*u*v*v-(u*u+v*v-w*w)*(u*u+v*v-w*w))/4.0;
	double temp;
	temp=(2*A)/(u+v+w);
	temp=(temp-r)/r*100;
	printf("%.3lf\n",temp);
}

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值