zoj 3177 Elune's Arrow(数学题,分类讨论)

Priestess of the Moon (PotM) is a very interesting hero in the game Defense of the Ancients (DotA). Here is the official description of PotM:

  • "A matriarch and high priestess of Elune's blessed order, Mirana Nightshade serves as a light in darkness for the front line of the Sentinel ranks, raining arrows and falling stars alike upon the shambling undead masses of the Undead Scourge, while her very presence is said to be so holy that it melts away the fatigue of nearby allies, giving them greater haste on the battlefield. In times of need however, she can fade herself and others around her into the safety of invisibility, making her a potent supporter matched by few."

She has a very powerful skill named Elune's Arrow. When she uses this ability, she fires an arrow to a location with deadly precision, dealing large damage and stunning the first unit it strikes. A powerful skill, but hard to manage, because the enemy never stands still waiting for your arrow, and you can't change the angle after you fires the arrow. For the sake of simplicity, you can assume that the enemy's body area is a circle with radius r0, the effective range of your arrow is also a circle with radius r1, and the enemy always runs in a straight line. Now, PotM is standing at (x1y1), while the enemy's position is (x0y0). The enemy's speed in both x and y directions can be represent by a vector (dxdy). So, after t minutes, the enemy's position will be (x0+dx*ty0+dy*t). The speed of PotM's arrow is v. If the effective range of the arrow touches the enemy's body area, it will be considered a strike, just like the collision of two circles. Now PotM wants to strike the enemy as soon as possible, could you help her to determine the time which the arrow takes to strike the enemy?

Input

The first line of the input contains a single number T (T <= 100), indicating the number of cases.

Each case consists of 5 lines, and each line contains the following decimal numbers: 

  • x0y0 (the enemy's initial position)
  • x1y1 (PotM's initial position)
  • dxdy (speed vector of the enemy)
  • r0r1 (radii of the circles of the enemy's body and the effective range of the arrow)
  • v, (positive speed of the arrow)
There is a blank line between the cases.
Note : the initial distance between PotM and the enemy will be larger than  r0 + r1 .

Output

For each case, output the least time (in minutes) PotM needs to strike the enemy(accurate up to 4 decimal places). If PotM cannot strike the enemy, just output "Impossible" in one line.

Sample Input

2
0.0 0.0
4.0 0.0
1.0 0.0
1.0 1.0
2.0

0.0 0.0
300.0 400.0
-3.0 -4.0
1.0 1.0
5.0

Sample Output

0.6667
Impossible
http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=3218

#include<iostream>
#include<algorithm>
#include<string>
#include<map>
#include<set>
#include<cmath>
#include<string.h>
#include<stdlib.h>
#include<cstdio>
#define ll long long
using namespace std;
int main(){
	int t;
	cin>>t;
	double x0,x1,y0,y1,dx,dy,r0,r1,v;
	while(t--){
		cin>>x0>>y0>>x1>>y1>>dx>>dy>>r0>>r1>>v;
		double a=v*v-dx*dx-dy*dy;
		double b=2*(v*(r0+r1)-(x0-x1)*dx-(y0-y1)*dy);
		double c=(r0+r1)*(r0+r1)-(x0-x1)*(x0-x1)-(y0-y1)*(y0-y1); //列出二元一次方程的a,b,c
		double d=b*b-4*a*c;
		if(a==0){    //分类讨论(一元一次方程时)
			if(b==0)
				cout<<"Impossible"<<endl;
			else{
				if(-c/b>0)       <span style="font-size: 12.380952835083px; font-family: Arial, Helvetica, sans-serif;">//判断答案的正负</span>
					printf("%.4lf\n",-c/b); 
				else
					cout<<"Impossible"<<endl;
			}
		}
		else if(d<0)  //无解时
			cout<<"Impossible"<<endl; 
		else{
			double s1=(-b-sqrt(d))/(2*a),s2=(-b+sqrt(d))/(2*a);
			if(s2<s1)
				swap(s1,s2); //两个值大小排序
			if(s1>=0)            //判断正负
				printf("%.4lf\n",s1);
			else if(s2>=0)
				printf("%.4lf\n",s2);
			else
				cout<<"Impossible"<<endl;
			}
		}
	return 0;
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值