(挑战编程_13_3)The Knights Of The Round Table

http://www.programming-challenges.com/pg.php?page=downloadproblem&probid=111303&format=html

#include <iostream>
#include <cstdlib>
#include <vector>
#include <map>
#include <string>
#include <cstring>
#include <fstream>
#include <cassert>
#include <cmath>
#include <iomanip>
#include <algorithm>
#include <sstream>
#include <queue>
#include <hash_map>


using namespace std;

//#define _MY_DEBUG_

const double PI = 3.1415926;

const double EPSILON = 1e-6;


/*
	MainStructure: 主结构
*/
void MainStructure();

/*
	Process
*/
void Process();

/*
	计算长度
*/
double CalLen(double a, double b, double c);


int main()
{
	MainStructure();
	return 0;
}


void MainStructure()
{
	
#ifdef _MY_DEBUG_
	string inputStr = "C:/Users/cao/Desktop/算法/要看的书/算法/2挑战编程/input/1.inp";
	//string inputStr = "D:/2挑战编程/input/110205.inp";
	string outputStr = "C:/Users/cao/Desktop/算法/要看的书/算法/2挑战编程/input/1.outp";
	ifstream fin;
	fin.open(inputStr);		

	cin.rdbuf(fin.rdbuf());	

	/*
	ofstream fout;
	fout.open(outputStr.c_str());
	cout.rdbuf(fout.rdbuf());
	*/

#endif

	Process();

}
void Process()
{
	string str;
	while (getline(cin, str))
	{
		if (str == "")
		{
			break;
		}
		stringstream ss(str);

		double a, b, c;
		ss >> a >> b >> c;
		double ans;
		if ((fabs(a) < EPSILON) || (fabs(b) < EPSILON) || (fabs(c) < EPSILON))
		{
			ans = 0;
		}
		else
		{
			double s = (a + b + c) / 2.000;
			ans = sqrt((s-a)*(s-b)*(s-c)/s);
		}
		printf("The radius of the round table is: %.3lf\n", ans);
	}

}

double CalLen(double a, double b, double c)
{
	double angle1 = acos((a * a + b * b - c * c) / (2 * a * b));
	// 出现0度或180度
	if ((fabs(angle1) < EPSILON) || (fabs(angle1 - PI) < EPSILON))
	{
		return 0;
	}
	angle1 /= 2;

	double angle2 = acos((b * b + c * c - a * a) / (2 * b * c));
	// 出现0度或180度
	if ((fabs(angle2) < EPSILON) || (fabs(angle2 - PI / 2) < EPSILON))
	{
		return 0;
	}
	angle2 /= 2;

	double tmp = 1 / (tan(angle1)) + 1 / (tan(angle2));
	double ans = b / tmp;

	return ans;
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值