2013 ACM/ICPC Changsha onsite competition C-collision (zoj 3728)

Source: Internet
Author: User
Tags cmath


Collision Time Limit: 2 seconds memory limit: 65536 kb Special Judge

There's a ro, the med,, the table, which is,. there's althat, ANY shar,, the specified, the,. 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 coinR, Radius of the Round rangeR, 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,VXAndVyIn 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


题意:http://blog.csdn.net/night_raven/article/details/16922749


AC代码:
 1 #include <iostream> 2 #include <sstream> 3 #include <cstdio> 4 #include <cstring> 5 #include <cmath> 6 #include <string> 7 #include <vector> 8 #include <set> 9 #include <cctype>10 #include <algorithm>11 #include <cmath>12 #include <deque>13 #include <queue>14 #include <map>15 #include <stack>16 #include <list>17 #include <iomanip>18 using namespace std;19 #define INF 0x7fffffff20 #define maxn 101021 #define eps 1e-1222 const double PI = acos(-1.0);23 typedef unsigned long long ull;24 25 double Rm, R, r, x, y, vx, vy;26 27 28 double dis(double k, double b)29 {30     return fabs(b) / sqrt(k*k + 1);31 }32 33 int main()34 {35     //freopen("out.txt", "w", stdout);36     while(~scanf("%lf%lf%lf%lf%lf%lf%lf", &Rm, &R, &r, &x, &y, &vx, &vy))37     {38         if(x*vx + y*vy >= 0) //相反方向移动!39         {40             printf("0.000\n");41             continue;42         }43         double k, b, d1;44         if(vx)  {45             k = vy / vx;46             b = y - k*x;47             d1 = dis(k, b);//运动轨迹与圆心距离48         }49         else d1 = fabs(x);50         if(d1 >= R+r) {51             printf("0.000\n");52             continue;53         }54 55         double v = sqrt(vx*vx + vy*vy);56 57         if(d1 >= Rm+r)//不会碰撞medal58             double len = 2*sqrt((R+r)*(R+r) - d1*d1);59         else60             double len = 2*(sqrt((R+r)*(R+r) - d1*d1) - sqrt((Rm+r)*(Rm+r) - d1*d1));61         printf("%.3lf\n", len / v);62     }63     return 0;64 }
View code

 

Note:

1. Determine whether the direction of motion is toward the center of the circle: x * VX + y * Vy <0;

2. Determine whether the motion track will enter the circular area: DIS> = R + R;

3. Determine if it will collide with medal: DIS <RM + R;

4. Accuracy: three decimal places;

 

2013 ACM/ICPC Changsha onsite competition C-collision (zoj 3728)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.