ZOJ3235 Prototype(数学)

题目链接: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 1
4 3 1 2 1 1

Sample Output

Yes
Yes

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-12

double 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,无解,全部标记为-1
	double t2=2*b*d2+sqrt(t1);
	double t3=2*b*d2-sqrt(t1);
	ans[0]=t2/(2*(a+b));//解1
	ans[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
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值