2015山东省第六届ACM-BIGZHUGOD and His Friends II(赛瓦定理+二分法求三次方程)
来源:互联网 发布:无镜片眼镜 知乎 编辑:程序博客网 时间:2024/05/05 04:52
题目描述
BIGZHUGOD and his three friends are playing a game in a triangle ground.The number of BIGZHUGOD is 0, and his three friends are numbered from 1 to 3. Before the game begins, three friends stand on three vertices of triangle in numerical order (1 on A, 2 on B, 3 on C), BIGZHUGOD stands inside of triangle.
Then the game begins, three friends run to the next vertex in uniform speed and in straight direction (1 to B, 2 to C, 3 to A and there speeds may different). And BIGZHUGOD can stand in any position inside the triangle.
When any of his friends arrives at next vertex, the game ends.
BIGZHUGOD and his friends have made an agreement: we assume that the beginning is time 0, if during the game, you can find a moment that BIGZHUGOD can block the sight line of 1 to C, 2 to A, 3 to B. Then each friend has to treat BIGZHUGOD with a big meal.
Now BIGZHUGOD knows the lengths of time that his three friends need run to next vertices t1, t2 and t3. He wants to know whether he has a chance to gain three big meals, of course he wants to know in which exciting moment t, he can block three friends\' sight line.
输入
The first line contains an integer T, indicating the number of test cases (T ≤ 1000).
For each case there are three integer t1, t2, t3 (1 ≤ t1, t2, t3 ≤ 100).
输出
If BIGZHUGOD has a chance to gain big meal from his friends, output "YES" and the exciting moment t rounding to 4 digits after decimal point. Otherwise, output "NO".
示例输入
2
1 1 1
3 4 6
示例输出
YES 0.5000
YES 2.0000
题意:BIGZHUGOD和3个人玩游戏,他站在三角形里边,3个人分别站在三角形的三个顶点,并依此朝下一个点走,他知道3个人走到下个点分别所用的时间t1,t2,t3,问是否有一个时刻,使得BIGZHUGOD挡住3个人和每个人相对点的视线,用下面的图来说,就是3个人到达E、F、D时,BIGZHUGOD赢。。
思路:
首先介绍一下赛瓦定理,
塞瓦定理是指在△ABC内任取一点O,延长AO、BO、CO分别交对边于D、E、F,则(BD/DC)×(CE/EA)×(AF/FB)=1
即:BD*CE*AF=DC*EA*FB;
本题f(x)=(t1-x)(t2-x)(t3-x)=x^3;求方程在[0,min(t1,min(t2,t3))]的解,误差在1e-5内.
然后就是套二分法求三次方程模板了。。。
以下AC代码:
#include<stdio.h>#include<math.h>int min(int a,int b){ return a<b?a:b;}int main(){ int t; int t1,t2,t3; scanf("%d",&t); while(t--) { scanf("%d%d%d",&t1,&t2,&t3); double f1=t1*t2*t3; int t=min(t1,min(t2,t3)); double x1=0,x2=t; double f2=(t1-x2)*(t2-x2)*(t3-x2)-x2*x2*x2; if(f1*f2>0) { printf("NO\n"); continue; } else if(f1==0) { printf("YES "); printf("%.4lf\n",x1); } else if(f2==0) { printf("YES "); printf("%.4lf\n",x2); } double x0,f0; int flag=0; do{ x0=(x1+x2)/2; f0=(t1-x0)*(t2-x0)*(t3-x0)-x0*x0*x0; if(f0*f1<0) { x2=x0; f2=f0; } else if(f0*f2<0) { x1=x0; f1=f0; } else { printf("YES "); printf("%.4lf\n",x0); flag=1; break; } }while(fabs(f0)>1e-5); if(!flag) { printf("YES "); printf("%.4lf\n",x0); } } return 0;}
1 0
- 2015山东省第六届ACM-BIGZHUGOD and His Friends II(赛瓦定理+二分法求三次方程)
- 山东省第六届ACM省赛题——BIGZHUGOD and His Friends II(塞瓦定理,二分求解方程)
- “浪潮杯”山东省赛 sdut 3256 BIGZHUGOD and His Friends II
- sdut 3256 BIGZHUGOD and His Friends II
- 山东省第六届ACM省赛题——Circle of Friends(强连通分量+dfs)
- 2015山东省第六届ACM省赛 Game!
- 2015山东省第六届ACM省赛 Nias and Tug-of-War
- 一元三次方程求解(二分法寻根)
- C代码:二分法求三次方程近似根
- 2015山东省第六届ACM省赛 Lowest Unique Price
- 2015山东省第六届ACM省赛 Single Round Math
- 2015山东省第六届acm省赛 C题Game!
- 山东省第六届 ACM 省赛 Stars (尺取法)
- 第五届山东省ACM Hearthstone II(Dp)
- 二分法求方程根
- 第六届山东省ACM竞赛 A题 Nias and Tug-of-War
- codeforces 66 D. Petya and His Friends(数论)
- 2014年山东省第五届ACM--Factorial (求阶乘)
- 一个问题
- 那些被漏掉的JQuery总结(五)——函数声明、函数表达式、匿名函数(立即执行、自执行)
- 数据库的一些基本语法一
- 面向切面编程之研究与探讨
- iOS多线程的初步研究(三)-- NSRunLoop
- 2015山东省第六届ACM-BIGZHUGOD and His Friends II(赛瓦定理+二分法求三次方程)
- 第九章案例分析
- Android官方文档之App Components(Common Intents)(转载)
- 关于java中Matcher类的find()之用法探究
- poj 2230
- angularjs学习笔记—事件指令
- java内存分配问题初学
- 数据库的一些基本语法二
- mysqldump详细了解