Area in Triangle(poj1927)

Area in Triangle
Time Limit: 1000MS Memory Limit: 30000K
Total Submissions: 1421 Accepted: 746

Description

Given a triangle field and a rope of a certain length (Figure-1), you are required to use the rope to enclose a region within the field and make the region as large as possible. 

Input

The input has several sets of test data. Each set is one line containing four numbers separated by a space. The first three indicate the lengths of the edges of the triangle field, and the fourth is the length of the rope. Each of the four numbers have exactly four digits after the decimal point. The line containing four zeros ends the input and should not be processed. You can assume each of the edges are not longer than 100.0000 and the length of the rope is not longer than the perimeter of the field.

Output

Output one line for each case in the following format: 

Case i: X 

Where i is the case number, and X is the largest area which is rounded to two digits after the decimal point. 

Sample Input

12.0000 23.0000 17.0000 40.0000
84.0000 35.0000 91.0000 210.0000
100.0000 100.0000 100.0000 181.3800
0 0 0 0

Sample Output

Case 1: 89.35
Case 2: 1470.00
Case 3: 2618.00

Source

[Submit]   [Go Back]   [Status]   [Discuss]





题意:

给一个三角形和一根绳子,求绳子在三角形内能围出的最大面积

solution:
分类讨论如下:

1.绳子很长,,如果比三边长之和还长,输出三角形面积即可

2.绳子很短,,如果比内接圆周长还短,输出绳子围一个圆的面积即可

3.这时绳子肯定是在三边上各有分布,之间用圆弧相连,可以把三个顶端和在一起,做一个小三角and小圆(画图),,,瞎比模拟之



细节处理不到位

#include<iostream>
#include<cstdio>
#include<queue>
#include<vector>
#include<bitset>
#include<algorithm>
#include<cstring>
#include<map>
#include<stack>
#include<set>
#include<cmath>
using namespace std;

typedef double DB;
const DB eps = 1E-10;
const DB pi = 3.14159265358979;

DB a,b,c,L,two = 2.00;

bool Judge() {return a <= eps && b <= eps && c <= eps && L <= eps;}

int main()
{
	
	for (int i = 1; ; i++) {
		scanf("%lf%lf%lf%lf",&a,&b,&c,&L);
		if (Judge()) break;
		DB p = (a + b + c)/two;
		DB s = sqrt(p*(p - a)*(p - b)*(p - c));
		if (a + b + c - L <= eps) {printf("Case %d: %.2lf\n",i,s); continue;} 		
		DB r = two*s/(a+b+c);
		if (two*pi*r - L >= eps) {
			DB R = L/pi/two;
			printf("Case %d: %.2lf\n",i,pi*R*R);
			continue;
		}
		DB x = (a+b+c-L);
		DB Lk = eps,Rk = 1.00;
		for (int j = 0; j < 100; j++) {
			DB mid = (Lk+Rk)/two;
			DB ck = mid*(a+b+c-two*pi*r);
			if (ck > x) Rk = mid; else Lk = mid;
		}
		DB sk = Rk*Rk*(s-pi*r*r);
		printf("Case %d: %.2lf\n",i,s - sk);
	}
	return 0;
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值