WOJ1062

Long time ago, people used to believe that they live on 2D world and if they will travel long enough in one direction, they will


fall down over the edge. Even when it was proved that the Earth is rounded some of them were still afraid to travel to southern hemisphere.
Try to imagine one 1D (linear) world. On such world there are only two possible directions (left and right). And there are two inhabitants
and one dog between them on such world. All of them will suddenly start to move at the same time. The two inhabitants move face to face
and the dog moves in one or the other direction. If the dog encounters any inhabitants it will change its direction and continue to run towards
the other one. The dog won?t stop until the two inhabitants encounter each other. You are ensured that the velocity of the two inhabitants
and the dog are constant in the running process.
Now, here comes the problem. Given the two inhabitants and dog?s initial positions, their velocity and the dog?s initial running direction,
can you tell me the total distance the dog running in its initial running direction?

输入格式

There are several test cases in input file. The first line of the input is a single integer T which is the number of test cases.
For each test case, the first line contains two integers a,u, representing the initial position and the velocity of one of two inhabitants.

The second line also contains two integers b,v, representing the initial position and the velocity of the other one. The third line contains
three integers c,p,d, representing the initial position, the velocity and the initial direction of the dog. You are ensured that au
and p>v, d=1 or d=-1(where 1 means left and -1 means right) and 0<=a,b,c,u,v,p<=2^16.

输出格式

For each test case, outputs the total distance the dog running in its initial running direction. The value must be accurate up to 3 decimal places.

样例输入

2
0 1
10 1
5 2 1
0 1
10 1
5 2 -1

样例输出

5.000
5.000

 

#include "stdio.h"
int main()
{
	int n,d;
	double a, b, u, v, c, p;
	scanf("%d", &n);
	while (n--)
	{
		double lenth;
		scanf("%lf%lf", &a, &u);
		scanf("%lf%lf", &b, &v);
		scanf("%lf%lf%d", &c, &p, &d);
		if (d == 1)
		{
			double t1 = (b - c) / (p + v);
			double d11 = a + t1 * u;
			double d12 = b - t1 * v;
			double t2 = (d12 - d11) / (p + u);
			double q = ((p - u)*(p - v)) / ((p + u)*(p + v));
			double tt = (b - a) / (u + v);
			double ttt = tt - t2 / (1 - q);
			lenth = ttt * p;
		}
		else if(d==-1)
		{
			double t1 = (c - a) / (p + u);
			double d11 = a + t1 * u;
			double d12 = b - t1 * v;
			double t2 = (d12 - d11) / (p + v);
			double q = ((p - u)*(p - v)) / ((p + u)*(p + v));
			double tt = (b - a) / (u + v);
			double ttt = tt - t2 / (1 - q);
			lenth = ttt * p;
		}
		printf("%.3lf\n", lenth);
	}
	return 0;
 }

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值