题目链接:http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=2896

大概思路:A和B运动,以A(Posa)为参考点,求出B的运动轨迹(Posb -> Posb + Vb-Va);

#include<cstdio>
#include<cstring>
#include<cmath>
#include<iostream>
#include<algorithm>
#include<queue>
using namespace std;
const int maxn = ;
const int maxe = ;
const int INF = 0x3f3f3f;
const double eps = 1e-;
const double PI = acos(-1.0); struct Point{
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);
} int dcmp(double x){ if(fabs(x) < eps) return ; else return x < ? - : ; } 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(Dot(A,A)); }
double Cross(const Vector& A, const Vector& B) { return A.x*B.y - A.y*B.x; } ///求点P到线段AB的距离,先看Q点在线段外还是内;利用点积就可以,
double DistanceToSegment(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)) < ) return Length(v2);
else if(dcmp(Dot(v1,v3) > )) return Length(v3);
else return fabs(Cross(v1,v2))/Length(v1);
} Point read_point(){
Point A;
scanf("%lf %lf",&A.x,&A.y);
return A;
} double Min, Max; void update(Point P,Point A,Point B){
Min = min(Min,DistanceToSegment(P,A,B));
Max = max(Max,Length(P-A));
Max = max(Max,Length(P-B));
} int main()
{
///freopen("E:\\acm\\input.txt","r",stdin);
///freopen("E:\\acm\\output.txt","w",stdout);
int T,a,b;
Point A[maxn],B[maxn];
cin>>T;
for(int t=;t<=T;t++){
cin>>a>>b;
for(int i=;i<=a;i++) A[i] = read_point();
for(int i=;i<=b;i++) B[i] = read_point(); double lenA = ,lenB = ;
for(int i=;i<a;i++) lenA += Length(A[i+]-A[i]);
for(int i=;i<b;i++) lenB += Length(B[i+]-B[i]); //这儿也能写错;复制就是不好。 int Sa = , Sb = ;
Point Posa = A[], Posb = B[]; // 现在甲乙所在的位置;
Min = 1e9, Max = -1e9;
while(Sa < a && Sb < b){
double La = Length(A[Sa+]-Posa);
double Lb = Length(B[Sb+]-Posb);
double T = min(La/lenA,Lb/lenB); // 取合适的单位,可以让甲和乙的速度分别是LenA和LenB
Vector Va = (A[Sa+]-Posa)/La * T * lenA; //A在这次比较下的位移向量;
Vector Vb = (B[Sb+]-Posb)/Lb * T * lenB;
update(Posa,Posb,Posb+Vb-Va); //Vb-Va是A在相对静止时,B的位移向量;
Posa = Posa + Va;
Posb = Posb + Vb;
if(Posa == A[Sa+]) Sa++;
if(Posb == B[Sb+]) Sb++;
}
printf("Case %d: %.0lf\n",t,Max-Min);
} return ;
}

UVa 11796 计算几何的更多相关文章

  1. ●UVA 11796 Dog Distance

    题链: https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem& ...

  2. UVA 11796 - Dog Distance 向量的应用

    http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&p ...

  3. 简单几何(相对运动距离最值) UVA 11796 Dog Distance

    题目传送门 题意:两只狗在折线上跑,速度未知,同时出发,同时达到.问跑的过程中,两狗的最大距离和最小距离的差 分析:训练指南P261,考虑相对运动,设A静止不动,B相对A运动,相对的运动向量:Vb - ...

  4. UVA 11796 - Dog Distance

    题意  两条狗啊,同时跑,,同时结束,各自跑各自的道路,问跑的过程中,他们最大距离和最小距离的差: 方法  恶心一点就是,最大最小距离的求解方法,假设两只狗都只有一条线段要跑,则可以判定在端点处有最大 ...

  5. UVA 11796 Dog Distance(向量)

    题目链接:http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=31962 [代码] #include<cstdio> # ...

  6. UVa 11178计算几何 模板题

    #include<cstdio> #include<cstring> #include<cmath> #include<iostream> #inclu ...

  7. UVA 11796

    题意:  有两个狗, 按照 多边形跑,不知道两条狗的速度,但是狗是同时出发,同时到达终点的 输出两条狗的 最大相距距离 - 最小相距距离: 思路 : 用物理的相对运动来计算, 每次只计算 两条狗的直线 ...

  8. UVA 11796 Dog Distance(几何)

    Dog Distance [题目链接]Dog Distance [题目类型]几何 &题解: 蓝书的题,刘汝佳的代码,学习一下 &代码: // UVa11796 Dog Distance ...

  9. UVa 11437:Triangle Fun(计算几何综合应用,求直线交点,向量运算,求三角形面积)

    Problem ATriangle Fun Input: Standard Input Output: Standard Output In the picture below you can see ...

随机推荐

  1. 【原创】不用封装jar包 直接引入工程使用的方法(类似android的 is Library功能)

    1.制作lib工程,这里我简单制作一个测试类 2.eclipse中 java Project工程引入方法 2.1.新建个java工程,在属性配置中选择 "Java Build Path&qu ...

  2. method=“post/get”

    Form表单中method="post/get'的区别   Form提供了两种数据传输的方式——get和post.虽然它们都是数据的提交方式,但是在实际传输时确有很大的不同,并且可能会对数据 ...

  3. iOS 中如何监测某段代码运行的时间

    在iOS里面有时间涉及到网络请求,有时间涉及到数据库的查询,我们需要计算该段代码的效率, 以及执行时间方面的问题,为此,可以使用下面方法: double a = CFAbsoluteTimeGetCu ...

  4. [转载]hadoop SecondNamenode详解

    SecondNamenode名字看起来很象是对第二个Namenode,要么与Namenode一样同时对外提供服务,要么相当于Namenode的HA.真正的了解了SecondNamenode以后,才发现 ...

  5. hdoj 1176(可转化为数塔)

    免费馅饼 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submissio ...

  6. Facade 模式

    在软件系统开发中经常回会遇到这样的情况,你实现了一些接口(模块),而这些接口(模块)都分布在几个类中(比如 A和 B.C.D) :A中实现了一些接口,B 中实现一些接口(或者 A代表一个独立模块,B. ...

  7. 关于浮动float属性和position:absolute属性的区别

    最近返回头看了很多书籍,一直在纠结float属性和absolute绝对定位的区别和使用的情况,给大家分享一下自己的心得和体会吧. 1,float属性 float属性意义是让元素拜托独占一行的霸道总裁, ...

  8. jquery中eq和get的区别与使用方法

    $("p").eq(0).css("color") //因为eq(num)返回的是个jq对象,所以可以用jq的方法css使用get来获得第一个p标签的color ...

  9. meta标签常用属性整理

    在segmentfault看到这篇文章,觉得整理的很详细,所以转载过来和大家分享一下. 原文地址:http://segmentfault.com/blog/ciaocc/119000000240791 ...

  10. [HttpClient]传递参数

    package com.jerry.httpclient; import java.io.UnsupportedEncodingException; import java.util.ArrayLis ...