大神写的太详细了,mark一下慢慢膜拜!~

http://blog.sina.com.cn/s/blog_493bff030100041r.html

There is a billiard table with acute triangle shape, and there are pockets at the three corners. A billiard ball hits the side of the table not at a
corner, it is reflected in the mirror direction. And it continues to travel on the table and we assume that the energy of this ball will not be
consumed, so the velocity of the ball is a constant number in the running process.

Now, you place the ball on any side of this billiard table and decide the slope of the line along which the ball starts at the origin. The trajectory
of the ball seems too complex to you, right? In order to simply this question, we will set restriction that the ball should bounce each side exactly
once and return to its start position at last. Under this restriction, can you find such trajectory that the time of ball running along it is shorter
than any other trajectories which satisfy this restriction?

输入格式

There are N test cases. The number of test cases N is given in the first line of the input file. For each test case, it contains six
integers (you are ensured that the absolute value of all the integers are less than) which specify the vertex point coordinates of the
acute triangle.

输出格式

You should output the length of the shortest trajectory.The answer should be accurate to three fractional digits exactly one line for each test case.

样例输入

2
0 0 2 0 1 2
0 0 2 0 1 3

样例输出

3.200
3.600

注意:题目要求小球和每边碰撞且只碰一次,最后回到出发点)    见图1

<> 分析题意:

根据对称,我们可以知道

DF = D’F

DE = D”E

AD = AD’= AD”

那么,求⊿DEF的周长可以转化为求折线D’F + FE + ED”的长度

又由于两个等腰三角形⊿ADD’和⊿ADD”,有下面的角度关系:

∠D’AD” =  ∠D’AB + ∠BAD + ∠DAC + ∠CAD”

=  2∠BAD + 2∠DAC = 2∠A

猜想:如果AD尽可能短,折线变成直线的话,那么所求就是最短的了。(可以想到垂线是最短的)

下面是具体的证明过程:

(1)       将D, E两点视为定点,求 DF + EF 的最小值  见图2

找点D关于边AB的对称点D”,当F为 D”E与AB的交点时,

DF + EF的值最小,

有  ∠DFB = ∠D”FB = ∠EFA

同理,将D, F两点视为定点, 有  ∠CED = ∠AEF

将E, F两点视为定点, 有  ∠BDF = ∠CDE

见图3

A + y + z = B + z + x = C + x + y = 180°

而 A + B + C = 180°

解得:x = A, y = B, z = C

(2)       设⊿DEF为垂足三角形,那么

因为AD, BE, CF为三高,B, D, E, A四点共圆,则有:∠CED = ∠B

C, E, F, D四点共圆,则有:    ∠AEF = ∠B

故: ∠CED = ∠AEF = ∠B

同理:∠BDF = ∠CDE = ∠A, ∠AFE = ∠BFD = ∠C

见图4 

<>

(3)       由(1)和(2)可知,⊿DEF为垂足三角形时,所得周长最短。

计算公式:

见图5

等腰三角形AD’D”中,

D’D” = 2 * AD * sinA ( 或2 * BE * sinB  或2 * CF * sinC )

AD = b * c * sinA / a

故D’D” = 2 * b * c * (1-cosA * cosA) / a;

#include <stdio.h>
#include <math.h>
double N_sqrt( int m0, int n0, int m1, int n1 ){return sqrt( pow((m0 - m1), 2) + pow((n0 - n1), 2) );
}
double line( int x0, int y0, int x1, int y1, int x2, int y2){
double a, b, c, cos_a, temp;a = N_sqrt( x0, y0, x1, y1);    b = N_sqrt( x0, y0, x2, y2);     c = N_sqrt( x1, y1, x2, y2);cos_a = (b*b + c*c - a*a) / (2.0*b*c);return 2*b*c*(1-cos_a*cos_a)/a;
}
int main(){int num;while(( scanf("%d", &num)!=EOF ) && ( num != 0 ) ) { double l[num]; for(int i=0; i<num; i++)  { int p[3][2]; for(int j=0; j<3; j++)   scanf("%d %d", &p[j][0], &p[j][1]); l[i] = line(p[0][0], p[0][1], p[1][0], p[1][1], p[2][0], p[2][1]);printf("%4.3f\n", l[i]);  } }return 0;
}

WOJ1017-Billiard Ball相关推荐

  1. linux入门级知识回顾

    ifdown eth0 #关闭网卡eth0 ifup eth0 #启动网卡eth0 ifconfig #查看网络配置:wq 保持并退出 :q 退出 :q! 强制退出不保存 :wq! 强制退出并保存 e ...

  2. 老男孩Linux运维第41期20171016第六周学习重点课堂记录

      Week6课堂知识点总结 作者:Old_Pan 归档:学习笔记 2017/10/16 目  录 第1章正则表达式与通配符... 2 1.1 特殊符号... 2 1.2 通配符... 3 1.3 { ...

  3. 正则表达式 特殊符号系列 通配符系列

    1.1 重定向符号 输出重定向 先清空文件,追加 追加输出重定向 追加 < 输入重定向 与 xargs tr << 追加输入重定向 cat 向一个文件追加多行. cat >&g ...

  4. 3.20 tr:替换或删除字符

    tr命令 从标准输入中替换.缩减或删除字符,并将结果写到标准输出. tr [option] [SET1]  [SET2] tr [选项]   [字符1]  [字符2] -d    删除字符 -s   ...

  5. 1、Linux命令随笔

    1 Linux命令总结 2 3 man ==命令帮助; 4 help ==命令的帮助(bash的内置命令); 5 ls ==list,查看目录列表; 6 -ld:查看目录权限; 7 -l:(long) ...

  6. vs 正则表达式转大写_liunx之通配符amp;正则表达式

    LIUNX之通配符 单引号双引号不加引号区别反引号 ''单引号所见即所得 ""双引号里面的特殊符号会被解析运行 $ LANG $()`` 不加引号和双引号类似支持通配符{} * 通 ...

  7. Linux扩展正则表达式

    1. 扩展正则表达式 1.1 +(加号) + 表示前一个字符出现1次或1次以上 1.1.1 理解+ 要求:取出文件内容连续出现的小写字母 [root@oldboyedu50-lnb /oldboy]# ...

  8. linux的特殊符号与正则表达式

    第1章 linux的特殊符号 1.1 通配符 * {} 1.1.1 含义 方便查找文件 通配符是用来找文件名字的. 1.1.2  * 通过find 命令找以 .sh 结尾的文件,使用*替代文件名字. ...

  9. 第四周day19-三剑客之awk

    补充-sed的后向引用 https://www.processon.com/view/link/5cb92f24e4b0bab9095ea765 筛选出stat /etc/hosts下的644 [✡r ...

最新文章

  1. Android开发之自定义Toast(带详细注释)
  2. python SSL error: [SSL: TLSV1_ALERT_PROTOCOL_VERSION] tlsv1 alert protocol version (_ssl.c:590) 解决方法
  3. ASP.NET 5 RC 1:UrlRouting 设置(不包含MVC6的UrlRouting设置)
  4. Delegate学习笔记
  5. MySQL查询不到中文的问题
  6. Transformation HDU - 4578
  7. 揭秘 | 小米最新款12PRO智能动态刷新率技术原理
  8. 学习爬虫过程中遇到的问题总结
  9. Oracle - SELECT 1 FROM table; SELECT COUNT(1) FROM table;
  10. 内核同步机制-优化屏障和内存屏障
  11. 分布式框架开发环境部署
  12. PHP打出来的数字和成语,php批量将词语 成语 导入数据库
  13. 高中计算机考察ppt,高中信息技术考察报告ppt课件.ppt
  14. 命名转小驼峰大驼峰中划线
  15. 雷军:我也想做高级工程师 !
  16. React-2-项目的创建
  17. [someip专题]vsomeip使用以及代码解析1
  18. 如何阅读matlab项目并调试运行成,【转】读书笔记:MATLAB
  19. firefox firbug 的“阻挡” blocking
  20. requests发送post请求到金山翻译

热门文章

  1. Python爬虫-IP隐藏技术与代理爬取
  2. HTML5 UI 模板
  3. Neutrino追问®AMA第7期|imToken商务总监:我们正在集成通过蓝牙安全使用的硬件钱包
  4. PLS-00905: 对象 SCOTT.QUERYEMPINFO 无效;PL/SQL: Statement ignored
  5. 用借款方实际付出的手续费(或利息)计算真实的手续费率(或利率),或快速估算年利率
  6. Android无法连接设备调试
  7. 鼠标拖拽盒子跟着鼠标在页面任意位置移动
  8. mac上配置cordova开发Android平台APP环境
  9. 以大学生活为主题html,大学生活散文800字范文-以校园生活为话题的抒情散文800字?...
  10. Gimp图像处理资料收集