您的位置:首页 > 其它

hdu-4793-Collision

2016-08-12 19:40 387 查看

Collision

[align=center][b]Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)[/b]
[/align]
[align=center][b]Total Submission(s): 822    Accepted Submission(s): 308[/b]
[/align]
[align=center][b]Special Judge[/b]
[/align]

[align=left]Problem Description[/align]
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 (x, y) and initial speed vector (vx, vy) 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.
 

[align=left]Input[/align]
There will be several test cases. Each test case contains 7 integers Rm, R, r, x, y, vx and vy in one line. Here 1 ≤ Rm < R ≤ 2000, 1 ≤ r ≤ 1000, R + r < |(x, y)| ≤ 20000, 1 ≤ |(vx, vy)| ≤ 100.
 

[align=left]Output[/align]
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.
 

[align=left]Sample Input[/align]

5 20 1 0 100 0 -1
5 20 1 30 15 -1 0

 

[align=left]Sample Output[/align]

30.000
29.394

 

[align=left]Source[/align]
2013 Asia Changsha Regional Contest

我们求时间的话,有两种情况时间始终为0.00,1是当不考虑碰撞时的运动轨迹是一条射线,射线所在直线距离原点的最短距离超过coin和region半径之和,2是本来coin就是越走越远,不可能进入圆环区域region

进入情况下,我们画出图即可写出表达式

我奇怪的一点是为什么读入以int读入就会WA

我们想如果是离原点越来越远的话,必然不会闯到区域region中来,也就是我们取一个最小的位移点,它必然距离会变大
除此之外我们考虑三种情况,coin距离原点的最短距离记为min_distance
1,最短距离大于R+r时,不会进入圆形区域



2,当最短距离小于R+r,而且小于Rm+r,此时不会发生碰撞



3,进入区域并发生碰撞 min_distance < R + r 并且 min_distance < Rm + r



Code

#include <iostream>
#include <cstdio>
#include <cmath>
using namespace std;
double Rm,R,r,x,y,vx,vy;
double min_distance,speed,min_distance_2;
int main()
{
while(scanf("%lf%lf%lf%lf%lf%lf%lf",&Rm,&R,&r,&x,&y,&vx,&vy) != EOF)/**/
{
if(x * x + y * y < (x + vx * 0.001) * (x + vx * 0.001) + (y + vy * 0.001) * (y + vy * 0.001))
{
puts("0.000");
continue;
}
speed = sqrt(vx * vx + vy * vy);
min_distance_2 = (vx * y - vy * x) * (vx * y - vy * x) / (double)(vx * vx + vy * vy);
min_distance = sqrt(min_distance_2);
if(min_distance >= R + r)
{
puts("0.000");
continue;
}
if(min_distance > r + Rm)
{
printf("%.3f\n",2 * sqrt((R + r) * (R + r) - min_distance_2) / speed);
continue;
}
printf("%.3f\n",2 * (sqrt((R + r) * (R + r) - min_distance_2) - sqrt((Rm + r) * (Rm + r) - min_distance_2))  / speed);
}
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  计算几何