Dog Distance UVA
来源:互联网 发布:补水保湿精华液 知乎 编辑:程序博客网 时间:2024/05/16 09:26
代码
struct Point{ Point() = default; double x,y; Point(double x,double y):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;}bool operator == (const Point &a,const Point &b){ return !dcmp(a.x-b.x)&&!dcmp(a.y-b.y);}//.....................................................//点乘double Dot(Vector A,Vector B){ return A.x*B.x+A.y*B.y;}//求模double Length(Vector A){ return sqrt(A.x*A.x+A.y*A.y);}//求斜率double Angle(Vector A,Vector B){ return acos(Dot(A,B)/Length(A)/Length(B));}//叉乘double Cross(Vector A,Vector B){ return A.x*B.y - A.y*B.x;}//求三角形面积double Area2(Point A,Point B,Point C){ return fabs(Cross(B-A,C-A))/2;}//旋转一定度数,弧度制Vector Rotate(Vector A,double rad){ return Vector (A.x*cos(rad)-A.y*sin(rad),A.x*sin(rad)+A.y*cos(rad));}//单位法线Vector Normal(Vector A){ double L = Length(A); return Vector(-A.y/L,A.x/L);}//调用前确保直线有唯一交点,当且仅当Cross(v,w)非0//求直线的交点Point Get_Line_Intersection(Point P,Vector v,Point Q,Vector w){ Vector u = P - Q; double t = Cross(w,u)/Cross(v,w); return P+v*t;}//点到直线的距离double Distance_To_Line(Point P,Point A,Point B){ Vector v1 = B-A,v2 = P-A; return fabs(Cross(v1,v2)/Length(v1));}//点到线段的距离double Distance_To_Segment(Point P,Point A,Point B){ if(A==B) return Length(P-A); Vector v1 = B-A,v2 = P-A,v3 = P-B; if(dcmp(Dot(v1,v2))<0) return Length(v2); else if(dcmp(Dot(v1,v3))>0) return Length(v3); else return fabs(Cross(v1,v2))/Length(v1);}//求投影点Point Get_Line_Projection(Point P,Point A,Point B){ Vector v = B- A; return A + v*(Dot(v,P-A)/Dot(v,v));}//线段相交判定 相交不在线段的端点bool Segment_Proper_Intersection(Point a1,Point a2,Point b1,Point b2){ double c1 = Cross(a2-a1,b1-a1),c2 = Cross(a2-a1,b2-a1), c3 = Cross(b2-b1,a2-b1),c4 = Cross(b2-b1,a1-b1); return dcmp(c1)*dcmp(c2)<0&&dcmp(c3)*dcmp(c4)<0;}//判断点是否在线段上(不包括端点)bool Onsegment(Point p,Point a1,Point a2){ return dcmp(Cross(a1-p,a2-p))==0&&dcmp(Dot(a1-p,a2-p))<0;}bool Intersect_Onsegment(Point a,Point b,Point c,Point d){ return Onsegment(a,c,d)||Onsegment(b,c,d)||Onsegment(c,a,b)||Onsegment(d,a,b);}Point a[100];Point b[100];double Min = inf,Max = -inf;void Update(Point A,Point B,Point C){ Min = min(Min,Distance_To_Segment(A,B,C)); Max = max(Max,Length(B-A)); Max = max(Max,Length(C-A));}int main(void){ int T; cin>>T; int kase = 0; int A,B; while(T--) { scanf("%d %d",&A,&B); for(int i = 0;i < A; ++i) scanf("%lf %lf",&a[i].x,&a[i].y); for(int i = 0;i < B; ++i) scanf("%lf %lf",&b[i].x,&b[i].y); double LenA = 0,LenB = 0; for(int i = 0;i < A-1; ++i) LenA += Length(a[i+1]-a[i]); for(int i = 0;i < B-1; ++i) LenB += Length(b[i+1]-b[i]); int Sa = 0,Sb = 0; Point Pa,Pb; Pa = a[0]; Pb = b[0]; Min = inf,Max = -inf; while(Sa<A-1&&Sb<B-1) { double da = Length(a[Sa+1]-Pa); double db = Length(b[Sb+1]-Pb); double T = min(da/LenA,db/LenB); Vector va = (a[Sa+1]-Pa)/da*T*LenA; Vector vb = (b[Sb+1]-Pb)/db*T*LenB; Update(Pa,Pb,Pb+vb-va); Pa = Pa + va; Pb = Pb + vb; if(a[Sa+1]==Pa) Sa++; if(b[Sb+1]==Pb) Sb++; } printf("Case %d: %.f\n",++kase,round(Max-Min)); } return 0;}
阅读全文
0 0
- UVA 11796 Dog Distance
- uva 11796 - Dog Distance
- UVA 11796 - Dog Distance
- UVA 11796Dog Distance
- UVA 11796 Dog Distance
- UVA 11796 Dog Distance
- UVA 11796 - Dog Distance
- UVA 11796 Dog Distance .
- Dog Distance UVA
- UVA 11796 Dog Distance 几何
- Dog Distance - UVa 11796 几何
- uva 11796 - Dog Distance(投影位移)
- UVA 11796 - Dog Distance 向量的应用
- 【UVA】11796 - Dog Distance(相对运动)
- uva 11796 Dog Distance(计算几何, 基础)
- UVA 11796 Dog Distance(点与向量)
- UVA - 11796 - Dog Distance (计算几何~)
- 相对运动模拟:UVa 11796 Dog Distance
- Git本地操作
- 分布式-锁
- RecycleView点击切换布局
- JavaScript类型转换
- 字符串
- Dog Distance UVA
- Mybatis(6):返回结果封装ResulMap的高级属性--association标签
- Burp Suite 界面介绍
- vmwear安装提示vmci.sys版本不对
- 安卓网络状态的判断与并提示设置
- 学习大数据的第一步-搭建Scala开发环境,以及使用Intellij IDEA开发Scala程序
- Html Agility Pack (HAP):c# HTML 解析利器
- 小more设计模式———简单工厂模式
- Git服务器建仓学习之路