题目链接: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. Encapsulation.

    Access control is often referred to as implementation hiding. Wrapping data and methods within class ...

  2. CI 笔记3 (easyui 的layout布局,最小化layout原型)

    在做easyui的layout的布局时,最小化一个原型,分2步,一个是div的父标签,一个是body做父标签,全屏的. 步骤分别为: 在设置的5个区中,div的最后一个,必须是data-options ...

  3. 网络编程(学习整理)---2--(Udp)实现简单的控制台聊天室

    1.UDP协议: 总结一下,今天学习的一点知识点! UDP也是一种通信协议,常被用来与TCP协议作比较!我们知道,在发送数据包的时候使用TCP协议比UDP协议安全,那么到底安全在哪里呢?怎么理解呢! ...

  4. Vijos1386 IOI2007 矿工配餐 动态规划

    感觉早些年IOI的题都不难啊,也就NOIp难度……现在貌似变难了 状态用dp[n][a1][b1][a2][b2]表示 n表示处理到前n个餐车 第一组矿工得到的最近一种食物用a1表示,a1的上一种食物 ...

  5. SGU 130.Circle

    答案为Catalan数C(2k, k)/(k+1) #include <stdio.h> using namespace std; int k; int main() { scanf(&q ...

  6. javascript——集合类

    /** * Created by Administrator on 2015/4/14. */ function Set() { this.values = {}; this.n = 0; this. ...

  7. PHPCMS V9 学习总结(转)

    转自:http://www.cnblogs.com/Braveliu/p/5074930.html 在实现PHPCMS网站过程中,根据业务需求,我们遇到很多问题,特此总结如下,以便大家参考学习. [1 ...

  8. PHP~foreach遍历名单数组~有必要多次观看练习

  9. asp.net中后台javaScrip的使用

    ClientScriptManager csm = Page.ClientScript;        //Script标记靠近<form>标签        //csm.Register ...

  10. dedecms 修改标题长度可以修改数据库

    数据表为dede__archives 字段为title 首先要在 a.系统->系统基本参数->其它选项->文章标题长度 b.系统->SQL命令行工具 alter table # ...