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了一次,没有判断方程解的非负性
 
 
 #include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#define eps 1e-8 /* >0:>eps--- <0:<-eps */
#define zero(x)(((x)>0?(x):-(x))<eps)
#define PI acos(-1.0)
#define LL long long
#define maxn 100100
#define IN freopen("in.txt","r",stdin);
using namespace std; int sign(double x)
{
if(fabs(x)<eps) return ;
return x<? -:;
} double Rm,R,r,x,y,vx,vy;
double v; int main(int argc, char const *argv[])
{
//IN; while(scanf("%lf%lf%lf%lf%lf%lf%lf",&Rm,&R,&r,&x,&y,&vx,&vy)!=EOF)
{
double a,b,c,del;
a = vx*vx+vy*vy;
b = 2.0*x*vx + 2.0*y*vy;
c = x*x + y*y - (R+r)*(R+r); del = (b*b - 4.0*a*c);
if(sign(del)<=) {printf("0\n");continue;} del=sqrt(del);
double t1,t2;
t1 = (-b+del)/(2.0*a);t2 = (-b-del)/(2.0*a);
if(t1>t2) swap(t1,t2);
if(t1<) {printf("0\n");continue;} a = vx*vx+vy*vy;
b = 2.0*x*vx + 2.0*y*vy;
c = x*x + y*y - (Rm+r)*(Rm+r); del = (b*b - 4.0*a*c);
if(sign(del)<=) {printf("%.3lf\n",fabs(t1-t2));continue;} del=sqrt(del);
double t3,t4;
t3 = (-b+del)/(2.0*a);t4 = (-b-del)/(2.0*a);
if(t3>t4) swap(t3,t4);
if(t3<) {printf("%.3lf\n",fabs(t1-t2));continue;} printf("%.3lf\n",2.0*fabs(t3-t1));
} return ;
}

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. GridView官方教程及示例

    Grid View GridView is a ViewGroup that displays items in a two-dimensional, scrollable grid. The gri ...

  2. python学习中,list/tuple/dict格式化遇到的问题

    昨天上了python培训的第一课,学习了基础知识.包括类型和赋值,函数type(),dir(),id(),help()的使用,list/tuple/dict的定义以及内置函数的操作,函数的定义,控制语 ...

  3. bzoj3672

    感觉是noi2014中最有价值的一道题了 我们先考虑链上这个问题怎么做…… 如果没限制,那就是SB的斜率优化 我们可以得到这个式子(f[j]-f[k])/(s[j]-s[k])<p[i] 点横坐 ...

  4. UVa 1515 (最小割) Pool construction

    题意: 输入一个字符矩阵,'.'代表洞,'#'代表草地.可以把草改成洞花费为d,或者把洞改成草花费为f,最后还要在草和洞之间修围栏花费为b. 但要保证最外一圈是草,求最小费用. 分析: 还不是特别理解 ...

  5. ubuntu12.04下txt文件乱码如何解决

    :gsettings set org.gnome.gedit.preferences.encodings auto-detected "['UTF-8','GB18030','GB2312' ...

  6. UVA 408 Uniform Generator 伪随机数(水)

    题意:根据这个式子来递推求得每个随机数x,step和mod给定,seed(0)=0.如果推出来的序列是mod个不重复的数字(0~mod-1)则打印good,否则bad(因为不能产生所有的数). 思路: ...

  7. AJAX在GBK编码页面中传中文参数乱码的问题

    ---恢复内容开始--- 页面编码是GBK的情况下传递中文有乱码,解决方法如下: 在ajax传递前用若是Array,JSON,等其它对象,可用JSON.stringfy字符串序列化后,赋值给ajax传 ...

  8. tomcat调优的几个方面

    转载自:http://my.oschina.net/u/593721/blog/146710 作者:小报童 和早期版本相比最新的Tomcat提供更好的性能和稳定性.所以一直使用最新的Tomcat版本. ...

  9. 【转】iOS自动布局进阶用法

    原文网址:http://www.cnblogs.com/dsxniubility/p/4266581.html 本文主要介绍几个我遇到并总结的相对高级的用法(当然啦牛人会觉得这也不算什么). 简单的s ...

  10. PHP经验集锦

    最近刚刚完成手中的项目,比较闲.来这儿转转,把积累的一些技巧分享给大家!1.关于PHP重定向 方法一:header("Location: index.php"); 方法二:echo ...