Collision

There's a round medal fixed on an ideal smooth table, Fancy is trying to throw some coins and make them slip towards the medal to collide. There's also a round range which shares exact the same center as the round medal, and radius of the medal is strictly less than radius of the round range. Since that the round medal is fixed and the coin is a piece of solid metal, we can assume that energy of the coin will not lose, the coin will collide and then moving as reflect.

Now assume that the center of the round medal and the round range is origin ( Namely (0, 0) ) and the coin's initial position is strictly outside the round range. Given radius of the medal Rm, radius of coin r, radius of the round range R, initial position (xy) and initial speed vector (vxvy) of the coin, please calculate the total time that any part of the coin is inside the round range.

Please note that the coin might not even touch the medal or slip through the round range.

Input

There will be several test cases. Each test case contains 7 integers RmRrxyvx and vy in one line. Here 1 ≤ Rm < R ≤ 2000, 1 ≤ r ≤ 1000, R + r < |(xy)| ≤ 20000, 1 ≤ |(vxvy)| ≤ 100.

Output

For each test case, please calculate the total time that any part of the coin is inside the round range. Please output the time in one line, an absolute error not more than 1e-3 is acceptable.

Sample Input
5 20 1 0 100 0 -1
5 20 1 30 15 -1 0
Sample Output
30.000
29.394
题意:光滑的桌面上放两个同心圆,一枚硬币以一定速度行驶,碰到小圆会反弹,求硬币部分在圆环中所花的总时间
#include<iostream>
#include<cstdio>
#include<cmath>
using namespace std;

int main()
{
	double Rm,R,r,x,y,vx,vy;
	while(scanf("%lf%lf%lf%lf%lf%lf%lf",&Rm,&R,&r,&x,&y,&vx,&vy)!=EOF)
	{
		double ans=0;
		Rm+=r; R+=r;
		double A=vx*vx+vy*vy;
		double B=2*x*vx+2*y*vy;
		double C1=x*x+y*y-R*R;
		double C2=x*x+y*y-Rm*Rm;
		double delta1=B*B-4*A*C1;
		double delta2=B*B-4*A*C2;
		if(delta1>0&&x*vx+y*vy<0)
		{
			if(delta2<=0) ans=fabs(sqrt(delta1)/A);
			else ans=fabs((sqrt(delta1)-sqrt(delta2))/A);
		}
		printf("%.3lf\n",ans);
	}
	return 0;
}

思路:转化成直线与圆的问题

注意:几何中整形数据可用浮点型输入



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值