ZOJ 3728 Collision

來源:互聯網
上載者:User

標籤:zoj   計算幾何   

CollisionTime 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 medalRm, 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 integersRm, 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 -15 20 1 30 15 -1 0
Sample Output
30.00029.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));        }    }}


ZOJ 3728 Collision

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.