码迷,mamicode.com
首页 > 其他好文 > 详细

[计算几何] zoj 3728 Collision

时间:2014-05-08 03:55:33      阅读:417      评论:0      收藏:0      [点我收藏+]

标签:style   blog   class   code   tar   ext   

题目链接:

http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3728


Collision

Time Limit: 2 Seconds      Memory Limit: 65536 KB      Special Judge

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

Author: FAN, Yuzhe
Contest: The 2013 ACM-ICPC Asia Changsha Regional Contest
Submit    Status


题目意思:

给一个以原点(0,0)为圆

心,半径为Rm固定的圆饼。给一个以原点(0,0)为圆心,半径为R的大圆。有一个圆硬币,圆心为(x,y),半径为r,速度为vx,vy,硬币碰到圆饼后会以同样的能量从反射方向弹回。求硬币从进入大圆开始到离开大圆所花的时间。

解题思路:

简单计算几何。

先把圆饼和大圆的半径都加上硬币的半径,这样就可以把硬币看成是一个点。

假设硬币在A点,原点为B点,运动方向向量为AC,先用点集(AB,AC)判断硬币运动,如果向量AB,AC夹角大于等于90度,肯定不会经过大圆。

然后用叉积求出AB在AC方向上距离(高)d。

如果d>R 与大圆无交点

如果Rm<d<R说明是直线穿过大圆(在大圆里面的运行距离为sqrt(R*R-d*d))

如果d<Rm说明先射向圆饼然后反弹(在大圆里的运行距离为2*(sqrt(R*R-d*d)-sqrt(Rm*Rm-d*d))

代码:

//#include<CSpreadSheet.h>

#include<iostream>
#include<cmath>
#include<cstdio>
#include<sstream>
#include<cstdlib>
#include<string>
#include<string.h>
#include<cstring>
#include<algorithm>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<ctime>
#include<bitset>
#include<cmath>
#define eps 1e-9
#define INF 0x3f3f3f3f
#define PI acos(-1.0)
#define ll __int64
#define LL long long
#define lson l,m,(rt<<1)
#define rson m+1,r,(rt<<1)|1
#define M 1000000007
//#pragma comment(linker, "/STACK:1024000000,1024000000")
using namespace std;

struct Point
{
    double x,y;
}p0,p1;
double Rm,R,r,x0,yy0,v;

double dianji(Point a,Point b)
{
    return a.x*b.x+a.y*b.y;
}
double chaji(Point a,Point b)
{
    return a.x*b.y-a.y*b.x;
}

int main()
{
   //freopen("in.txt","r",stdin);
   //freopen("out.txt","w",stdout);
   while(~scanf("%lf%lf%lf",&Rm,&R,&r))
   {
       Rm+=r,R+=r;
       scanf("%lf%lf",&x0,&yy0);
       scanf("%lf%lf",&p1.x,&p1.y);

       v=sqrt(p1.x*p1.x+p1.y*p1.y);

       p0.x=-x0,p0.y=-yy0;

       if(dianji(p0,p1)<eps)
       {
           printf("0.000\n");
           continue;
       }
       //system("pause");
       double d=fabs(chaji(p0,p1))/v;

       if(d-R>eps) //在外面
       {
           printf("0.000\n");
           continue;
       }
       if(d-Rm>eps)
       {
           printf("%.3lf\n",2*sqrt(R*R-d*d)/v);
           continue;
       }
       printf("%.3lf\n",(2*(sqrt(R*R-d*d)-sqrt(Rm*Rm-d*d)))/v);


   }
   return 0;
}



[计算几何] zoj 3728 Collision,布布扣,bubuko.com

[计算几何] zoj 3728 Collision

标签:style   blog   class   code   tar   ext   

原文地址:http://blog.csdn.net/cc_again/article/details/25243095

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!