题目链接: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. android Services注意地方

    使用service前需要在manifest声明: <manifest ... > ... <application ... > <service android:name ...

  2. wpf 调用线程必须为sta 因为许多ui组件都需要

    解决 办法 public void SomeMethod() { var task = System.Windows.Application.Current.Dispatcher.BeginInvok ...

  3. Spring通过SchedulerFactoryBean实现调度任务的配置

    http://blog.csdn.net/hu_shengyang/article/details/19815201(里面是配置) 介绍SchedulerFactoryBean http://blog ...

  4. Deep Learning 学习随记(八)CNN(Convolutional neural network)理解

    前面Andrew Ng的讲义基本看完了.Andrew讲的真是通俗易懂,只是不过瘾啊,讲的太少了.趁着看完那章convolution and pooling, 自己又去翻了翻CNN的相关东西. 当时看讲 ...

  5. Wpf自定义路由事件

    创建自定义路由事件大体可以分为三个步骤: ①声明并注册路由事件. ②为路由事件添加CLR事件包装. ③创建可以激发路由事件的方法. 以ButtonBase类中代码为例展示这3个步骤: public a ...

  6. 【BZOJ3110】【整体二分+树状数组区间修改/线段树】K大数查询

    Description 有N个位置,M个操作.操作有两种,每次操作如果是1 a b c的形式表示在第a个位置到第b个位置,每个位置加入一个数c 如果是2 a b c形式,表示询问从第a个位置到第b个位 ...

  7. phpcms(4) V9 栏目管理

    phpcms V9框架系统后台管理之栏目管理,请参见下文的源码分析(添加栏目和修改栏目): 参照添加栏目的界面图示,便于对源代码的理解: <?php   // 文件路径:phpcms/modul ...

  8. css清除浮动方法大全

    清除浮动这个问题,做前端的应该再熟悉不过了,也是每一个web前台设计师 必须掌握的机能. 为什么浮动这么难? 因为浮动会使当前标签产生向上浮的效果,同时会影响到前后标签.父级标签的位置及 width ...

  9. Visual Studio 2013 在使用 MVC5 无智能提示

    关于 Visual Studio 2013 在使用 MVC5 无智能提示的问题,类库无法正常识别,连最基本的关键字提示都没有了,类变色也没有了,所有的关键字代码,类名,方法成员名都要全部手动敲 原因: ...

  10. php之文件上传简单介绍

    要声明的form表单格式 <form action="act.php" method="post" enctype="multipart/for ...