HDU - 4793 Collision
2014-10-09 14:15
344 查看
水几何。
#include <iostream> #include <cstdio> #include <cstring> #include <cstdlib> #include <algorithm> #include <vector> #include <string> #include <cmath> using namespace std; 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); } Vector operator - (Vector a, Vector b) { return Vector(a.x-b.x, a.y-b.y); } Vector operator * (Vector a, double p) { return Vector(a.x*p, a.y*p); } Vector operator / (Vector a, double p) { return Vector(a.x/p, a.y/p); } bool operator <(const Point &a, const Point &b) { return a.x<b.x || (a.x==b.x && a.y<b.y); } const double eps=1e-10; int dcmp(double x) { if(fabs(x)<eps)return 0; else return x<0?-1:1; } double dot(Vector a, Vector b) { return a.x*b.x+a.y*b.y; } double Length(Vector a) { return sqrt(dot(a, a)); } double cross(Vector a, Vector b) { return a.x*b.y-a.y*b.x; } Point get_line_projection(Point p, Point a, Point b) { Vector v=b-a; return a+v*(dot(v, p-a)/dot(v, v)); } double gougu(double c, double a) { return sqrt(c*c-a*a); } double Rm, R, r; Point s, v; Vector L; int main() { while(~scanf("%lf%lf%lf%lf%lf%lf%lf", &Rm, &R, &r, &s.x, &s.y, &v.x, &v.y)) { if(Length(s+v)>Length(s-v)) { printf("0.000\n"); continue ; } if(!dcmp(v.y)) { L.x=0; L.y=10; } else { L.x=10.0; L.y=-1.0*v.x*10.0/v.y; } Point P=get_line_projection(s, Point(0, 0), L); //投影点 double dis=Length(P); //投影点到原点距离 if(dcmp(dis-R-r)>0) { printf("0.000\n"); continue ; } double dis1=gougu(R+r, dis); if(dcmp(dis-Rm-r)>0) { printf("%.3lf\n", 2*dis1/sqrt(v.x*v.x+v.y*v.y)); continue ; } double dis2=gougu(Rm+r, dis); printf("%.3lf\n", 2*(dis1-dis2)/sqrt(v.x*v.x+v.y*v.y)); } return 0; }
相关文章推荐
- HDU 4793 2013 Changsha Regional Collision[简单的平面几何]
- HDU 4793 2013 Changsha Regional Collision[简单的平面几何]
- HDU 4793 Collision(计算几何)——2013 Asia Changsha Regional Contest
- HDU 4793 Collision【计算机几何】【经典】
- HDU 4793 Collision【计算几何】
- HDU 4793 Collision 【计算几何】
- HDU-4793 Collision 计算几何 解方程
- HDU 4793 Collision(2013长沙区域赛现场赛C题)
- hdu-4793-Collision
- HDU 4793 Collision --解方程
- HDU 4793 Collision + HDU 4798 Skycity 简单几何
- HDU 4793 Collision --解方程
- HDU 4793 Collision (解二元一次方程) -2013 ICPC长沙赛区现场赛
- hdu 4793 Collision(几何)
- HDU 5114 Collision(一元线性同余方程)
- Collision (hdu-5114
- hdu 5114 Collision
- 数学(扩展欧几里得算法):HDU 5114 Collision
- Collision (hdu-5114)
- hdu 5114 Collision (扩展欧几里得)