ZOJ3235 Prototype(数学)

来源:互联网 发布:ps软件那里下载 编辑:程序博客网 时间:2024/04/29 03:36

题目链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=3492


Prototype

Time Limit: 1 Second      Memory Limit: 32768 KB

Prototype is a 3D game which allow you to control a person named Alex with much super ability to finish missions with gut along. Alex has the abilitiy to glide in the sky. What's more, he can make at most 3-level glide, which means before he lands at the ground, he has two chances to adjust and perform another glide. We assume that each time he perform a glide, his vertical speed become zero and glide forward with a new speed. And the orbit will be a parabola due to the gravity.

To make the problem easier, we now only consider at most 2-level glide. The binomial coefficient of the mathematical equation of the fist glide will be given as -a and the second will be -b, which means the formulations are (y - y0) = -ax2 and (y - y0) = -b(x - x0)2. As the picture above, Alex perform a glide from the top of Building1, make a 1-level or a 2-level glide and lands exactly at point B. What's more, there is Building2 standing between Building1 and point B. Alex has to avoid crashing onto it.

Input

There are no more than 15 cases. Proceed till the end of file.
Each case contains only one line of six real number h1h2d1d2abh1 is the height of Building1, h2 is the height of Building2, d1 is the X-distance between Building1 and Building2, d2 is the X-distance between point B and Building1. These four numbers are in [0, 1000] , and satisfies d1 < d2. And a and b are in (0, 1000].

Output

If it is possible for Alex to land exactly on point B, print Yes, otherwise print No.

Sample Input

25 1 6 7 1 14 3 1 2 1 1

Sample Output

YesYes

HINT

In case 2, Alex just glide over the building2 and do not crash onto it.


题意:一个会二段跳的guy站在楼1顶上,现在他要跳到位于地面上的B点,给出每段跳的方程,问guy是否能不撞到建筑2到达B。


一道数学题,实际上不难,就是计算很复杂(不过也就高中数学),还要注意细节处理(不可能到达B的情况)


方法:先求出对于B点,应该在那个位置进行二段跳,记为(xx,yy),然后看建筑2在xx的左边还是右边,在左边就代入方程1,右边就是方程2,然后判断有没有相撞即可。

注意点1:B点若离楼1太近,则肯定无法到达。(以直接从楼1顶开始二段跳为准,小于这个距离的都无法到达)

注意点2:B点若离楼1太远,则也无法到达.(判断方程是否有解即可)


另外,解方程会得到两个解,不清楚怎么舍,干脆一起考虑了。ORZ

方程不难求,输入不方便就不写了。ORZ


#include <iostream>#include <cstdio>#include <cstring>#include <string>#include <cmath>using namespace std;#define eps 1e-12double h1,h2,d1,d2,a,b,ans[2];int dcmp(double x){return (x>eps)-(x<-eps);}void qj(){double t1=4*b*b*d2*d2-4*(a+b)*(b*d2*d2-h1);//方程的Δif (dcmp(t1)<0) {ans[0]=-1;ans[1]=-1;return;}//Δ小于0,无解,全部标记为-1double t2=2*b*d2+sqrt(t1);double t3=2*b*d2-sqrt(t1);ans[0]=t2/(2*(a+b));//解1ans[1]=t3/(2*(a+b));//解2}int main(){while (scanf("%lf%lf%lf%lf%lf%lf",&h1,&h2,&d1,&d2,&a,&b)!=EOF){int flag[2];flag[0]=0;flag[1]=0;if (dcmp(h1/b-d2*d2)>0) {printf("No\n");continue;}//B离楼1太近,无解qj();for (int i=0;i<2;i++){double xx=ans[i];if(dcmp(xx)<0) {flag[i]=0;continue;}//B离楼1太远也无解double yy=-a*xx*xx+h1;double ansy;if (dcmp(d1-xx)>0){ansy=-b*(d1-xx)*(d1-xx)+yy;}else{ansy=-a*d1*d1+h1;}if (dcmp(ansy-h2)<0) flag[i]=0;else flag[i]=1;//不会撞到就标记为1}if (flag[0]==1) printf("Yes\n");else if (flag[1]==1) printf("Yes\n");else printf("No\n");//两个解都不行输出No}}


0 0