Area in Triangle(计算几何基础)
2017-08-17 12:06
351 查看
描述:
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.
输入:
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 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.
样例输入:
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
样例输出:
Case 1: 89.35
Case 2: 1470.00
Case 3: 2618.00
题目大意:
给你一个三角形和一根绳要求用绳在三角形内围出最大的面积。
#include<stdio.h>
#include<math.h>
const double PI=(2.0*asin(1.0));
int main()
{
double a,b,c,d,l,max;
double R,r,triple,area;
int cas=1;
scanf("%lf %lf %lf %lf",&a,&b,&c,&d);
while(a+b+c+d)
{
triple=a+b+c;
l=triple*0.5;
area=sqrt(l*(l-a)*(l-b)*(l-c)); //三角形面积
R=area*2.0/triple; //三角形内切圆面积
if(a+b+c<=d) //有三种情况1.绳子的长度长于三角形周长2.绳子的长度小于三角形内切圆周长3.处于一二两种情况之间
max=area; //第一种情况最大面积就是三角形面积
else if(2.0*PI*R>=d)
max=d*d/(4.0*PI); //第二中情况只要算出能围成的最大圆面积是多少就是答案了
else
{
r=(a+b+c-d)/((a+b+c)/R-2.0*PI);
max=area+PI*r*r-(r*r*area/(R*R));
}
printf("Case %d: %.2f\n",cas++,max);
scanf("%lf %lf %lf %lf",&a,&b,&c,&d);
}
return 0;
}
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.
输入:
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 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.
样例输入:
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
样例输出:
Case 1: 89.35
Case 2: 1470.00
Case 3: 2618.00
题目大意:
给你一个三角形和一根绳要求用绳在三角形内围出最大的面积。
#include<stdio.h>
#include<math.h>
const double PI=(2.0*asin(1.0));
int main()
{
double a,b,c,d,l,max;
double R,r,triple,area;
int cas=1;
scanf("%lf %lf %lf %lf",&a,&b,&c,&d);
while(a+b+c+d)
{
triple=a+b+c;
l=triple*0.5;
area=sqrt(l*(l-a)*(l-b)*(l-c)); //三角形面积
R=area*2.0/triple; //三角形内切圆面积
if(a+b+c<=d) //有三种情况1.绳子的长度长于三角形周长2.绳子的长度小于三角形内切圆周长3.处于一二两种情况之间
max=area; //第一种情况最大面积就是三角形面积
else if(2.0*PI*R>=d)
max=d*d/(4.0*PI); //第二中情况只要算出能围成的最大圆面积是多少就是答案了
else
{
r=(a+b+c-d)/((a+b+c)/R-2.0*PI);
max=area+PI*r*r-(r*r*area/(R*R));
}
printf("Case %d: %.2f\n",cas++,max);
scanf("%lf %lf %lf %lf",&a,&b,&c,&d);
}
return 0;
}
相关文章推荐
- POJ 1927 Area in Triangle(计算几何)
- Area in Triangle (计算几何)
- POJ 1654 Area 计算几何基础
- poj1584 A Round Peg in a Ground Hole 判断多边形凹凸,点到线的距离【基础计算几何】
- In-circles Again(计算几何基础)
- nyis oj 68 三点顺序 (计算几何基础)
- POJ 1654 Area 计算几何
- 【POJ1584】A Round Peg in a Ground Hole,第一次的计算几何
- poj 1654 Area ----- 计算几何
- 计算几何基础
- AIZU OJ 2308 基础计算几何学习
- 计算几何基础——矢量和叉积
- ACM-计算几何之The area——hdu1071
- 计算几何基础与一般模板:POJ 3675&&ZOJ 1450&&POJ 1375
- 计算几何基础
- 计算几何--POJ--1654--Area
- POJ 1518 A Round Peg in a Ground Hole【计算几何=_=你值得一虐】
- poj1265 Area(计算几何)
- HDU 4946 - Area of Mushroom (计算几何 凸包)
- Toy Storage(二维计算几何基础)