hdu4793Collision
来源:互联网 发布:淘宝店铺地址怎么修改 编辑:程序博客网 时间:2024/05/03 17:50
2013年亚洲区域赛长沙站的几何题,就是告诉你两个圆(大圆和小圆),同心的,再告诉你一个小小圆在大圆外面,再告诉你小小圆的运动速度(矢量),如果碰到小圆就原路返回,如果碰不到就穿过大圆,问你小小圆在大圆中的时间。一开始忘了判断速度方向,如果反向,就为0s,wa了n遍。。。。
具体做法,求圆心到小小圆运动直线的最短距离,如果大于R+r就为0,如果小于R+r但大于Rm+r就根据勾股定理求出在大圆中一半的距离,除以速度再乘2就是时间了,如果小于等于Rm+r也是根据勾股定理求出在大圆中的距离,除以速度再乘2。
#include<cstdio>#include<cstring>#include<cstdlib>#include<cmath>#define eps 1e-8#define zero(x) (((x)>0?(x):(-x))<eps)using namespace std;double Rm,R,r;struct point{ double x,y; point (double x=0,double y=0):x(x),y(y) {}};typedef point Vector;Vector operator +(Vector A, Vector B){ return Vector(A.x+B.x , A.y+B.y);}struct line{ point a,b;};double xmult(point p1,point p2,point p0){ return (p1.x-p0.x)*(p2.y-p0.y)-(p2.x-p0.x)*(p1.y-p0.y);}double Dot(Vector A,Vector B){ return A.x*B.x+A.y*B.y;}point intersection(point u1,point u2,point v1,point v2){ point ret=u1; double t=((u1.x-v1.x)*(v1.y-v2.y)-(u1.y-v1.y)*(v1.x-v2.x))/((u1.x-u2.x)*(v1.y-v2.y)-(u1.y-u2.y)*(v1.x-v2.x)); ret.x+=(u2.x-u1.x)*t; ret.y+=(u2.y-u1.y)*t; return ret;}point ptoline(point p,point l1,point l2)//点到直线距离{ point t=p; t.x+=l1.y-l2.y,t.y+=l2.x-l1.x; return intersection(p,t,l1,l2);}double distance(point p1,point p2){ return sqrt((p1.x-p2.x)*(p1.x-p2.x)+(p1.y-p2.y)*(p1.y-p2.y));}double disptoline(point p,line l){ return fabs(xmult(p,l.a,l.b))/distance(l.a,l.b);}int main(){ point v,s; point st; line stt; while(~scanf("%lf%lf%lf%lf%lf%lf%lf",&Rm,&R,&r,&s.x,&s.y,&v.x,&v.y)) { if(Dot(s,v)>=0) { printf("%lf\n",0.0); continue; } stt.a=s,stt.b=s+v; point tmp = ptoline(st,stt.a,stt.b); double dis = distance(tmp,st); double H = R+r,h = Rm+r; double speed = sqrt((v.x*v.x)+(v.y*v.y)); { if(dis>=H) { printf("%lf\n",0.0); } else { if(dis>=h) { double dist = sqrt((H*H)-(dis*dis)); printf("%.3lf\n",dist/speed*2.0); } else { double dist = sqrt((H*H)-(dis*dis))-sqrt((h*h)-(dis*dis)); printf("%.3lf\n",dist/speed*2.0); } } } } return 0;}
0 0
- hdu4793Collision
- 浏览器或webApp跳转nativeApp应用
- SerializationException 无法捕捉(catch)
- DB2实例(查看参数及修改)
- 自动检测文本文件编码是否为GB2312(简体中文),并转换为UTF8编码,附一个GB2312全区对应的utf8编码码表
- 自协商功能原理及工作过程
- hdu4793Collision
- C++基础篇--overload重载&override覆盖&overwrite隐藏
- 面试总结-阿里巴巴
- Web 服务编程,REST 与 SOAP
- Servlet.service() for servlet [spring] in context with path [] threw exception [Request processing f
- Face Alignment at 3000 FPS 学习理解和具体实现
- 朴素贝叶斯
- C++基础系列(4)
- android实现火箭升空清理内存