题目链接:http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=31962

【代码】

 #include<cstdio>
#include<cmath>
#include<algorithm>
using namespace std; const double eps = 1e-;
int dcmp(double x) { if(fabs(x) < eps) return ; else return x < ? - : ; } struct Point {
double x, y;
Point(double x=, double y=):x(x),y(y) { }
}; typedef Point Vector; Vector operator + (const Vector& A, const Vector& B) { return Vector(A.x+B.x, A.y+B.y); }
Vector operator - (const Point& A, const Point& B) { return Vector(A.x-B.x, A.y-B.y); }
Vector operator * (const Vector& A, double p) { return Vector(A.x*p, A.y*p); }
Vector operator / (const 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);
} bool operator == (const Point& a, const Point &b) {
return dcmp(a.x-b.x) == && dcmp(a.y-b.y) == ;
} Point read_point() {
double x, y;
scanf("%lf%lf", &x, &y);
return Point(x, y);
}; double Dot(const Vector& A, const Vector& B) { return A.x*B.x + A.y*B.y; }
double Length(const Vector& A) { return sqrt(Dot(A, A)); }
double Cross(const Vector& A, const Vector& B) { return A.x*B.y - A.y*B.x; } double DistanceToSegment(const Point& P, const Point& A, const 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);
} const int maxn = ;
int T, A, B;
Point P[maxn], Q[maxn];
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() {
scanf("%d", &T);
for(int kase = ; kase <= T; kase++) {
scanf("%d%d", &A, &B);
for(int i = ; i < A; i++) P[i] = read_point();
for(int i = ; i < B; i++) Q[i] = read_point(); double LenA = , LenB = ;
for(int i = ; i < A-; i++) LenA += Length(P[i+]-P[i]);
for(int i = ; i < B-; i++) LenB += Length(Q[i+]-Q[i]); int Sa = , Sb = ;
Point Pa = P[], Pb = Q[];
Min = 1e9, Max = -1e9;
while(Sa < A- && Sb < B-) {
double La = Length(P[Sa+] - Pa);
double Lb = Length(Q[Sb+] - Pb);
double T = min(La/LenA, Lb/LenB);
Vector Va = (P[Sa+] - Pa)/La*T*LenA;
Vector Vb = (Q[Sb+] - Pb)/Lb*T*LenB;
update(Pa, Pb, Pb+Vb-Va);
Pa = Pa + Va;
Pb = Pb + Vb;
if(Pa == P[Sa+]) Sa++;
if(Pb == Q[Sb+]) Sb++;
}
printf("Case %d: %.0lf\n", kase, Max-Min);
}
return ;
}

UVA 11796 Dog Distance(向量)的更多相关文章

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

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

  2. UVA 11796 Dog Distance(几何)

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

  3. ●UVA 11796 Dog Distance

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

  4. UVA 11796 - Dog Distance

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

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

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

  6. UVa 11796 计算几何

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

  7. UVA 10140 - Prime Distance(数论)

    10140 - Prime Distance 题目链接 题意:求[l,r]区间内近期和最远的素数对. 思路:素数打表,打到sqrt(Max)就可以,然后利用大的表去筛素数.因为[l, r]最多100W ...

  8. UVA 11437 - Triangle Fun 向量几何

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

  9. UVA 11796

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

随机推荐

  1. AcroExch.Rect 单位、属性问题

    AcroExch.Rect  有四个属性:Top,Right,Left,Buttom 1.单位:point,一般通过英寸换算,1point=1/72 inch(英寸) 2.属性:Top: 区域距离 x ...

  2. 跨域的小小总结:js跨域及跨域的几种解决方法

    一.什么是跨域?? js跨域请求就是使用js访问iframe里的不同域名下的页面内容,比如用ajax向一个不同的域请求数据,或者通过js获取页面中不同的域的iframe框架中的数据.即只要域名.协议. ...

  3. Objective-C发展历史

    Objective-C发展历史 苹果图标由来: 被咬了一口苹果的LOGO是为了纪念计算机科学的创始人阿兰· 麦席森· 图灵.当年图灵由于身为同性恋者,被强行 "治疗",在被迫注射大 ...

  4. 转:探讨android更新UI的几种方法

    本文转自:http://www.cnblogs.com/wenjiang/p/3180324.html 作为IT新手,总以为只要有时间,有精力,什么东西都能做出来.这种念头我也有过,但很快就熄灭了,因 ...

  5. 【转】ASP.NET MVC教程

    转自:http://www.cnblogs.com/QLeelulu/category/123326.html ASP.NET MVC的最佳实践与性能优化的文章 摘要: 就一些文章链接,就不多废话了. ...

  6. 祭奠一年前写 Direct2D demo

    一年前, 用Direct2D实现了不怎么样的UI库. 用不怎么样的UI库实现了这个Demo. 当时放进某群共享, 以此装逼. 今天无意中翻出来, 解压, 什么都没变, 还是压缩前的模样. 不经意看见被 ...

  7. Introduction to object

    1 Declarations VS definitions     (Page 81)     declarations: This function or variable exists somew ...

  8. android入门到熟练(二)----活动

    1.活动创建对于每一个后端java类(继承至Activity或者ActionBarActivity)代码都有一个方法需要被重写[onCreate], 在此方法中可以加载界面资源文件或者绑定元素事件. ...

  9. 彻底弄清c标准库中string.h里的常用函数用法

    在我们平常写的c/c++程序,一些算法题中,我们常常会用到c标准库中string.h文件中的函数,这些函数主要用于处理内存,字符串相关操作,是很有用的工具函数.而且有些时候,在笔试或面试中也会出现让你 ...

  10. bootstrap轮播组件,大屏幕图片居中效果

    在慕课网学习bootstrap轮播组件的时候,了解到轮播的图片都放在了类名为item下的img中 视频中老师对图片自适应采用给图片img设置width=100%完成,然而这样自适应处理图片在不同屏幕中 ...