• 博客园logo
  • 会员
  • 周边
  • 新闻
  • 博问
  • 闪存
  • 众包
  • 赞助商
  • Chat2DB
    • 搜索
      所有博客
    • 搜索
      当前博客
  • 写随笔 我的博客 短消息 简洁模式
    用户头像
    我的博客 我的园子 账号设置 会员中心 简洁模式 ... 退出登录
    注册 登录
HaibaraAi
博客园    首页    新随笔    联系   管理    订阅  订阅

2013 Asia Changsha Regional Contest Problem C

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

 1 #include <cstdio>
 2 #include <vector>
 3 #include <cmath>
 4 #include <queue>
 5 #include <cstring>
 6 #include <iostream>
 7 #include <algorithm>
 8 using namespace std;
 9 #define INF 0x7fffffff
10 #define mod 1000000007
11 #define ll long long
12 #define maxn 1005
13 double rm, rr, r, x, y, vx, vy, a, b, c, d, d1, d2, v, x2, y2;
14 int main(){
15     while (~scanf("%lf%lf%lf%lf%lf%lf%lf", &rm, &rr, &r, &x, &y, &vx, &vy)){
16         v = sqrt(vx*vx + vy*vy);
17         y2 = y + vy; x2 = x + vx;
18         a = (y2 - y); b = -(x2 - x); c = y*b + x*a;
19         d = fabs(c) / sqrt(a*a + b*b);
20         if (x*vx + y*vy >= 0){ printf("0.000\n"); continue; }
21         d1 = sqrt(fabs((rr + r)*(rr + r) - d*d));
22         d2 = sqrt(fabs((rm + r)*(rm + r) - d*d));
23         if (d - rr - r >= 0){ printf("0.000\n"); continue; }
24         if (d - rm - r >= 0)printf("%.3lf\n", 2.0*d1 / v);
25         else printf("%.3lf\n", 2.0 * (d1 - d2) / v);
26 
27     }
28     return 0;
29 }
View Code
posted @ 2013-12-16 04:49  HaibaraAi  阅读(98)  评论(0)    收藏  举报
刷新页面返回顶部
博客园  ©  2004-2026
浙公网安备 33010602011771号 浙ICP备2021040463号-3