[计算几何] zoj 3728 Collision

题目链接:

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

时间: 2024-10-11 07:45:55

[计算几何] zoj 3728 Collision的相关文章

ZOJ 3728 Collision

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

2013 ACM/ICPC 长沙现场赛 C题 - Collision (ZOJ 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

简单几何(直线与圆的交点) ZOJ Collision 3728

题目传送门 题意:有两个一大一小的同心圆,圆心在原点,大圆外有一小圆,其圆心有一个速度(vx, vy),如果碰到了小圆会反弹,问该圆在大圆内运动的时间 分析:将圆外的小圆看成一个点,判断该直线与同心圆的交点,根据交点个数计算时间.用到了直线的定义,圆的定义,直线与圆交点的个数. /************************************************ * Author :Running_Time * Created Time :2015/10/24 星期六 16:14:

ZOJ 3720 Magnet Darts (计算几何,概率,判点是否在多边形内)

http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3720 题意: 在一个矩形区域投掷飞镖,因此飞镖只会落在整点上,投到每个点的得分是Ax+By.矩形区域里面有个多边形,如果飞镖投在多边形里面则得分,求最终的得分期望. 即:给定一个矩形内的所有整数点,判断这些点是否在一个多边形内 方法: 计算几何的判点是否在多边形内(几何模板),如果在,则令得分加(Ax+By)*以此点为中心边长为1的正方形面积 1 void solve()

ZOJ 3762 Pan&#39;s Labyrinth 计算几何

题意:给出一系列的坐标,要求出这些坐标中组成的三角形中最大的高是多少 下列两个假设必然有一个成立 1.点C是所有点中距离点A最远的 2.点C是所有点中距离点B最远的 #include<cstdio> #include<cmath> #include<cstring> #include<algorithm> #include<iostream> using namespace std; struct point { double x,y; }p[5

HDU 4793 Collision (2013长沙现场赛,简单计算几何)

Collision Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 685    Accepted Submission(s): 248Special Judge Problem Description There's a round medal fixed on an ideal smooth table, Fancy is tryin

ZOJ 3203 Light Bulb (三分+计算几何)

题目地址:ZOJ 3203 第一发三分.三分的原理还是挺简单的. 代码如下: #include <iostream> #include <string.h> #include <math.h> #include <queue> #include <algorithm> #include <stdlib.h> #include <map> #include <set> #include <stdio.h&g

ZOJ 1696 Viva Confetti 计算几何

计算几何:按顺序给n个圆覆盖,问最后可以有几个圆被看见... 对每个圆求和其他圆的交点,每两个交点之间就是可能被看到的圆弧,取圆弧的中点,往外扩展一点或者往里缩一点,从上往下判断有没有圆可以盖住这个点,能盖住这个点的最上面的圆一定是可见的 Viva Confetti Time Limit: 2 Seconds      Memory Limit: 65536 KB Do you know confetti? They are small discs of colored paper, and p

ZOJ 1081 Within(点是否在多边形内)| 计算几何

ZOJ 1081 Within 我使用的是"射线法":从该点出发,作一条向左的水平射线,与多边形的边的交点有奇数个则点在多边形内. 需要注意的点: 如果点在多边形的边上特判. 考虑射线与多边形的一个交点是多边形的顶点的情况, 最左边的那个顶点算一个交点,左边第二种的那个顶点算两个交点或不算交点都行(但不能算一个交点). #include <cstdio> #include <cstring> #include <cmath> #include <