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 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.

Input

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.

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

题目链接 :http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3728

题目大意 :有一个圆硬币半径为r,初始位置为x,y。速度矢量为vx。vy,有一个圆形区域(圆心在原点)半径为R。另一个圆盘(圆心在原点)半径为Rm (Rm < R),圆盘固定不动,硬币撞到圆盘上会被反弹,不考虑能量损失。求硬币在圆形区域内运动的时间。

题目分析 :设硬币的运动方程为x‘ = x + vxt。y‘ = y + vyt,分别带入以(r + R) 和 (r + Rm)为半径的圆方程,与大圆联立无解或者有负解则为0,与大圆联立有无负解与小圆联立无解则直接解为(t2- t1)可用韦达定理处理。|t2 - t1| = sqrt(derta) / a,若与小圆联立有负解则为0,否则解为2*(t‘),t‘为先撞到圆盘时的t

#include <cstdio>
#include <cmath>
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 a = vx * vx + vy * vy;
        double b = 2 * (x * vx + y * vy);
        double c1 = x * x + y * y - (R + r) * (R + r);
        double c2 = x * x + y * y - (Rm + r) * (Rm + r);
        double derta1 = b * b - 4 * a * c1;
        double derta2 = b * b - 4 * a * c2;
        double t1 = (-b + sqrt(derta2)) / (2 * a);
        double t2 = (-b - sqrt(derta2)) / (2 * a);
        double t3 = (-b + sqrt(derta1)) / (2 * a);
        double t4 = (-b - sqrt(derta1)) / (2 * a);
        if(derta1 <= 0)
            printf("0.000\n");
        else if(derta1 > 0 && derta2 <= 0)
        {
            if(t3 < 0 || t4 < 0)
                printf("0.000\n");
            else
                printf("%.3f\n", sqrt(derta1) / a);
        }
        else if(derta2 > 0)
        {
            double t11 = fabs(t1 - x) > fabs(t2 - x) ? t2 : t1;
            double t22 = fabs(t3 - x) > fabs(t4 - x) ? t4 : t3;
            if(t11 < 0 || t22 < 0)
                printf("0.000\n");
            else
                printf("%.3f\n", 2 * fabs(t22 - t11));
        }
    }
}
时间: 2024-12-18 19:26:15

ZOJ 3728 Collision的相关文章

[计算几何] 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

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:

图论 500题——主要为hdu/poj/zoj

转自——http://blog.csdn.net/qwe20060514/article/details/8112550 =============================以下是最小生成树+并查集======================================[HDU]1213   How Many Tables   基础并查集★1272   小希的迷宫   基础并查集★1325&&poj1308  Is It A Tree?   基础并查集★1856   More i

概率dp ZOJ 3640

Help Me Escape Time Limit:2000MS     Memory Limit:32768KB     64bit IO Format:%lld & %llu Submit Status Practice ZOJ 3640 Appoint description:  System Crawler  (2014-10-22) Description Background     If thou doest well, shalt thou not be accepted? an

zoj 2156 - Charlie&#39;s Change

题目:钱数拼凑,面值为1,5,10,25,求组成n面值的最大钱币数. 分析:dp,01背包.需要进行二进制拆分,否则TLE,利用数组记录每种硬币的个数,方便更新. 写了一个 多重背包的 O(NV)反而没有拆分快.囧,最后利用了状态压缩优化 90ms: 把 1 cents 的最后处理,其他都除以5,状态就少了5倍了. 说明:貌似我的比大黄的快.(2011-09-26 12:49). #include <stdio.h> #include <stdlib.h> #include <

ZOJ 1718 POJ 2031 Building a Space Station 修建空间站 最小生成树 Kruskal算法

题目链接:ZOJ 1718 POJ 2031 Building a Space Station 修建空间站 Building a Space Station Time Limit: 2 Seconds      Memory Limit: 65536 KB You are a member of the space station engineering team, and are assigned a task in the construction process of the statio

ZOJ 3607 Lazier Salesgirl (贪心)

Lazier Salesgirl Time Limit: 2 Seconds      Memory Limit: 65536 KB Kochiya Sanae is a lazy girl who makes and sells bread. She is an expert at bread making and selling. She can sell the i-th customer a piece of bread for price pi. But she is so lazy

ZOJ - 2243 - Binary Search Heap Construction

先上题目: Binary Search Heap Construction Time Limit: 5 Seconds      Memory Limit: 32768 KB Read the statement of problem G for the definitions concerning trees. In the following we define the basic terminology of heaps. A heap is a tree whose internal n