Collision

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 685    Accepted Submission(s): 248
Special Judge

Problem Description
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
 
Source
 
 
【题意】:
圆心在原点的两个同心圆,半径是Rm和R,还有一个半径为r的硬币,给出初始位置和速度矢量,
硬币与内圆碰撞后会等动能反弹,求硬币在大圆区域内运动的时间。。。
 
【解题思路】:
在t时刻,硬币的位置为P(x+Vx*t, y+Vy*t)把P分别代到x^2+y^2=(R+r)^2 和 x^2+y^2=(Rm+r)^2(一定要加 r )中,可以求出硬币与大小圆接触的时间点
根据方程的解的情况判断:若与大圆无2个交点输出0;若与内圆无2个交点输出t1-t2;
若发生碰撞,则输出2*(t3-t1); —— 若碰撞,则入射与反射路径对称,长度必然相等
WA了一次,没有判断方程解的非负性
 
 
  1. #include<iostream>
  2. #include<cstdio>
  3. #include<cstring>
  4. #include<cmath>
  5. #include<algorithm>
  6. #define eps 1e-8 /* >0:>eps--- <0:<-eps */
  7. #define zero(x)(((x)>0?(x):-(x))<eps)
  8. #define PI acos(-1.0)
  9. #define LL long long
  10. #define maxn 100100
  11. #define IN freopen("in.txt","r",stdin);
  12. using namespace std;
  13.  
  14. int sign(double x)
  15. {
  16. if(fabs(x)<eps) return ;
  17. return x<? -:;
  18. }
  19.  
  20. double Rm,R,r,x,y,vx,vy;
  21. double v;
  22.  
  23. int main(int argc, char const *argv[])
  24. {
  25. //IN;
  26.  
  27. while(scanf("%lf%lf%lf%lf%lf%lf%lf",&Rm,&R,&r,&x,&y,&vx,&vy)!=EOF)
  28. {
  29. double a,b,c,del;
  30. a = vx*vx+vy*vy;
  31. b = 2.0*x*vx + 2.0*y*vy;
  32. c = x*x + y*y - (R+r)*(R+r);
  33.  
  34. del = (b*b - 4.0*a*c);
  35. if(sign(del)<=) {printf("0\n");continue;}
  36.  
  37. del=sqrt(del);
  38. double t1,t2;
  39. t1 = (-b+del)/(2.0*a);t2 = (-b-del)/(2.0*a);
  40. if(t1>t2) swap(t1,t2);
  41. if(t1<) {printf("0\n");continue;}
  42.  
  43. a = vx*vx+vy*vy;
  44. b = 2.0*x*vx + 2.0*y*vy;
  45. c = x*x + y*y - (Rm+r)*(Rm+r);
  46.  
  47. del = (b*b - 4.0*a*c);
  48. if(sign(del)<=) {printf("%.3lf\n",fabs(t1-t2));continue;}
  49.  
  50. del=sqrt(del);
  51. double t3,t4;
  52. t3 = (-b+del)/(2.0*a);t4 = (-b-del)/(2.0*a);
  53. if(t3>t4) swap(t3,t4);
  54. if(t3<) {printf("%.3lf\n",fabs(t1-t2));continue;}
  55.  
  56. printf("%.3lf\n",2.0*fabs(t3-t1));
  57. }
  58.  
  59. return ;
  60. }

HDU 4793 Collision (2013长沙现场赛,简单计算几何)的更多相关文章

  1. HDU 4793 Collision(2013长沙区域赛现场赛C题)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4793 解题报告:在一个平面上有一个圆形medal,半径为Rm,圆心为(0,0),同时有一个圆形范围圆心 ...

  2. HDU 4800/zoj 3735 Josephina and RPG 2013 长沙现场赛J题

    第一年参加现场赛,比赛的时候就A了这一道,基本全场都A的签到题竟然A不出来,结果题目重现的时候1A,好受打击 ORZ..... 题目链接:http://acm.hdu.edu.cn/showprobl ...

  3. HDU 4791 Alice's Print Service (2013长沙现场赛,二分)

    Alice's Print Service Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Ot ...

  4. hdu 4813(2013长春现场赛A题)

    把一个字符串分成N个字符串 每个字符串长度为m Sample Input12 5 // n mklmbbileay Sample Outputklmbbileay # include <iost ...

  5. HDU 5531 Rebuild (2015长春现场赛,计算几何+三分法)

    Rebuild Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 262144/262144 K (Java/Others)Total S ...

  6. HDU 4816 Bathysphere (2013长春现场赛D题)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4816 2013长春区域赛的D题. 很简单的几何题,就是给了一条折线. 然后一个矩形窗去截取一部分,求最 ...

  7. HDU 4815 Little Tiger vs. Deep Monkey(2013长春现场赛C题)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4815 简单的DP题. #include <stdio.h> #include <st ...

  8. 2013长沙网络赛H题Hypersphere (蛋疼的题目 神似邀请赛A题)

    Hypersphere Time Limit: 1 Second       Memory Limit: 32768 KB In the world of k-dimension, there's a ...

  9. 2013杭州现场赛B题-Rabbit Kingdom

    杭州现场赛的题.BFS+DFS #include <iostream> #include<cstdio> #include<cstring> #define inf ...

随机推荐

  1. Support Library官方教程(2)各支援包的特性详介(含表)*

    快速阅读 包名  作用  位置 是否有资源 v4 提供了最多的api <sdk>/extras/android/support/v4/ y Multidex 把DEX文件生成apk < ...

  2. NDK(15)在ndk代码中注册和注销native函数

    转自:  http://www.cnblogs.com/canphp/archive/2012/11/13/2768937.html C和C++注册native函数的方式大致上相同,下面给出具体的代码 ...

  3. Oracle Create DBLink

    DROP PUBLIC DATABASE LINK ORA11G_DBLINK; CREATE   PUBLIC   DATABASE LINK ORA11G_DBLINKCONNECT TO SYS ...

  4. vi编辑器基本用法介绍

    vi是Linux系统中编写文件的工具 如果vi出现乱码情况,需要升级vi,命令如下: sudo apt-get install vim  //升级vi vi的启动方式有两种,直接使用vi命令和在vi命 ...

  5. js对联广告代码,兼容性高

    var browser = { ie6: function () { return ((window.XMLHttpRequest == undefined) && (ActiveXO ...

  6. 图形数据库、NOSQL和Neo4j

    简介 在众多不同的数据模型里,关系数据模型自80年代就处于统治地位,而且有不少实现,如Oracle.MySQL和MSSQL,它们也被称为关系数据库管理系统(RDBMS).然而,最近随着关系数据库使用案 ...

  7. <一>SQL优化1-4

    第一条:去除在谓词列上编写的任何标量函数        --->在select 显示列上使用标量函数是可以的.但在where语句后的过滤条件部分对列使用函数,需要考虑.因为执行sql的引擎会因为 ...

  8. C语言指针5分钟教程

    指针.引用和取值 什么是指针?什么是内存地址?什么叫做指针的取值?指针是一个存储计算机内存地址的变量.在这份教程里“引用”表示计算机内存地址.从指针指向的内 存读取数据称作指针的取值.指针可以指向某些 ...

  9. web自动化框架之三获取数据库值与界面值比较~~

    数据库用到的是mysql,框架涉及数据库,主要包含两个方面,一个是每个案例执行完毕后,插入案例相关信息与数据:一个是web界面数据核对的时候,需要从sql中获取某行某列值与界面某个值做比较. 描述:w ...

  10. Windows套接字Socket函数

    1.使用套接字函数之前,先要加载套接字函数库: #include "Winsock2.h" #pragma comment(lib,"Ws2_32.lib") ...