“浪潮杯”山东省赛 sdut 3256 BIGZHUGOD and His Friends II
来源:互联网 发布:思迅软件合作伙伴社区 编辑:程序博客网 时间:2024/05/21 22:16
题目描述
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
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
塞瓦定理加二分法求3次方程
#include<iostream>#include<cstring>#include<cstdio>#include<cmath>#include<algorithm>using namespace std;int main(){ int T; cin>>T; while(T--) { int t1,t2,t3; cin>>t1>>t2>>t3; int t=min(t1,min(t3,t2)); double x1=0,x2=t; double f1=t1*t2*t3; double f2=(t1-x2)*(t2-x2)*(t3-x2)-x2*x2*x2; if(f1*f2>0) { cout<<"NO"<<endl; continue; } else if(f1==0) { cout<<"YES"<<" "; printf("%0.4f\n",x1); } else if(f2==0) { cout<<"YES"<<" "; printf("%0.4f\n",x2); } double x0,f0; bool 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 { cout<<"YES"<<" "; printf("%0.4f\n",x0); flag=1; break; } }while(fabs(f0)>1e-5); if(!flag) { cout<<"YES"<<" "; printf("%0.4f\n",x0); } } return 0;}
塞瓦定理是指在△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;1
求方程在[0,max(t1,max(t2,t3))]的解,误差在1e-5内
用二分法求方程
求方程f=2x^3-4x^2+3x-6=0在区间[-10,10]的解,误差在1e-5的模板
double x1,x2; cin>>x1>>x2; double f1,f2; f1=((2*x1-4)*x1+3)*x1-6; f2=((2*x2-4)*x2+3)*x2-6; if(f1*f2>0) cout<<"无解"<<endl; else if(f1==0) { cout<<x1<<endl; return 0; } else if(f2==0) { cout<<x2<<endl; return 0; } double x0,f0; do { x0=(x1+x2)/2; f0=((2*x0-4)*x0+3)*x0-6; if(f0*f1<0) { x2=x0; f2=f0; } else if(f0*f2<0) { x1=x0; f1=f0; } else { cout<<x0<<endl; return 0; } }while(fabs(f0)>=1e-5);//abs是取绝对值后再取整,而fabs是取绝对值之后不做操作cout<<x0<<endl;
1 0
- “浪潮杯”山东省赛 sdut 3256 BIGZHUGOD and His Friends II
- sdut 3256 BIGZHUGOD and His Friends II
- 2015山东省第六届ACM-BIGZHUGOD and His Friends II(赛瓦定理+二分法求三次方程)
- 山东省第六届ACM省赛题——BIGZHUGOD and His Friends II(塞瓦定理,二分求解方程)
- 第6届山东省浪潮杯 Circle of Friends SDUT3262
- 第6届山东省浪潮杯 Circle of Friends SDUT3262
- “浪潮杯”山东省第6届acm省赛 sdut3258 Square Number sdut 3257 Cube Number
- SDUT 3561 Fibonacci (“浪潮杯”山东省第七届ACM大学生程序设计竞赛)
- Problem F: ZZY and his little friends
- CSU1323: ZZY and his little friends
- CF 66D Petya and His Friends
- CodeForces515B Drazil and His Happy Friends (数学)
- B. Drazil and His Happy Friends
- 515B. Drazil and His Happy Friends
- B. Drazil and His Happy Friends
- CSU1323: ZZY and his little friends
- B. Drazil and His Happy Friends
- 关于第八届浪潮杯(山东省赛)
- UI控件--AlertDialog
- 设计模式 (3)用例图之二
- onAnimationEnd不一定能执行
- ssh 证书方式远程登陆linux主机
- WebLogic、WebSphere、JBOSS、Tomcat之间的区别 2
- “浪潮杯”山东省赛 sdut 3256 BIGZHUGOD and His Friends II
- 同步
- POJ1287 Networking(最小生成树)
- flex&&bison
- 一个Android图片(视频)选择器:android-media-picker
- Java动态代理
- HDU 1012 u Calculate e
- 飛飛(十七)用递归方法求a!
- 7 面向对象(成员变量和局部变量的区别,类作为形式参数的问题,匿名对象,封装,private关键字,this关键字,构造方法,类的初始化过程,static关键字)