HDU 1451 Area in Triangle(相似三角形)
来源:互联网 发布:java 引用class文件 编辑:程序博客网 时间:2024/05/16 08:37
Area in Triangle
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 221 Accepted Submission(s): 63
Problem 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.
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.000084.0000 35.0000 91.0000 210.0000100.0000 100.0000 100.0000 181.38000 0 0 0
Sample Output
Case 1: 89.35Case 2: 1470.00Case 3: 2618.00
Source
ACM暑期集训队练习赛(六)
题目大意:给你三角形的三边长,给你一根绳长,问线能在三角形中围成的最大面积。
这道题目需要分情况讨论
1.如果绳子比三角形周长长,那么围成的最大面积就是三角形面积。
2.绳子比三角形周长短。
2.1绳子比三角形内切圆的周长短。
我们要知道,在平面内,在周长一定的情况下,圆的面积最大。
所以围成的最大面积为以绳长为周长的圆的面积。
2.2绳子比三角形内切圆的周长长
那么绳子肯定会与三角形的三条边都有贴合的部分,贴合的部分可以看成三个矩形,未贴合的部分就是三个圆弧,三个圆弧可以组成里面相似三角形的内切圆。(图不是很标准)
利用的就是三角形相似的原理;
公式;p0/R*(R-r)=len-2*pi*R;
左边是通过内切圆半径与周长的关系求得小三角形的周长;右边是通过自由线的长度减掉三段弧得到相似三角形的周长;
那么最后的围成的最大面积就是相似三角形面积+相似三角形内切圆面积+三个矩形的面积
以下是AC代码
#include<cstdio>#include<cmath>using namespace std;#define eps 1e-9#define pi acos(-1.0)int main(){ int T=0; double a,b,c,len,p0,p1,S,R,r; //len为自由线的长度;p0为原三角形的周长;p1为原三角形的半周长; //R为原三角形的内切圆半径;r为相似三角形的内切圆半径。 while(scanf("%lf%lf%lf%lf",&a,&b,&c,&len),a+b+c+len) { printf("Case %d: ",++T); p0=a+b+c; p1=p0/2; S=sqrt(p1*(p1-a)*(p1-b)*(p1-c)); if(len>=p0) {printf("%.2lf\n",S);continue;} //自由线长大于三角形周长 R=2*S/p0; //三角形内切圆公式S=p0*R/2; R为内切圆半径 if(2*pi*R-len>eps) { R=len/pi/2; S=pi*R*R; printf("%.2lf\n",S); continue; } //利用的就是三角形相似的原理;公式;p0/R*(R-r)=len-2*pi*R;左边是通过内切圆半径与周长的关系求 //得小三角形的周长;右边是通过自由线的长度减掉三段弧得到相似三角形的周长; r=(p0-len)/(p0/R-2*pi);//三角形相似 a=a/R*(R-r); b=b/R*(R-r); c=c/R*(R-r); double p=(a+b+c)/2; S=pi*r*r+sqrt(p*(p-a)*(p-b)*(p-c))+r*(a+b+c);//分三个部分求面积 printf("%.2lf\n",S); }}原题链接:HDU 1451
阅读全文
1 0
- HDU 1451 Area in Triangle(相似三角形)
- Area in Triangle(计算几何基础)
- Area in Triangle (计算几何)
- Area in Triangle
- Area in Triangle(poj1927)
- POJ 1927 Area in Triangle
- H - Area in Triangle解题报告(熊禾强)
- POJ 1927 Area in Triangle(计算几何)
- POJ-1927 Area in Triangle解题报告
- POJ 1927 Area in Triangle 笔记
- 倒三角形(triangle)
- 倒三角形(triangle)
- 倒三角形(triangle)
- 倒三角形(triangle)
- 倒三角形(triangle)
- HDU 4082(计算几何+相似三角形)
- hdu 4082 计算几何 相似三角形
- LeetCode 120. Triangle(三角形)
- 基站系统
- Elasticsearch5.3 如何创建mapping demo
- Vue.js学习笔记-2-MVVM
- C语言中的进制关系
- 2015ali android挑战赛第二题之反调试技术解析
- HDU 1451 Area in Triangle(相似三角形)
- 华为OJ——字符串排序
- wifi状态下实现文件传输
- 【翻译】--docker get started 02
- Spring 和Mybatis整合的时候使用的三种数据源
- 指针和引用的区别
- 海德公寓main
- 提供任意字符串,js写一个函数能够查找字符串中出现最多的次数的字符及其个数。
- 迭代器模式