UVA 11796 Dog Distance(向量)
题目链接: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(向量)的更多相关文章
- UVA 11796 - Dog Distance 向量的应用
http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&p ...
- UVA 11796 Dog Distance(几何)
Dog Distance [题目链接]Dog Distance [题目类型]几何 &题解: 蓝书的题,刘汝佳的代码,学习一下 &代码: // UVa11796 Dog Distance ...
- ●UVA 11796 Dog Distance
题链: https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem& ...
- UVA 11796 - Dog Distance
题意 两条狗啊,同时跑,,同时结束,各自跑各自的道路,问跑的过程中,他们最大距离和最小距离的差: 方法 恶心一点就是,最大最小距离的求解方法,假设两只狗都只有一条线段要跑,则可以判定在端点处有最大 ...
- 简单几何(相对运动距离最值) UVA 11796 Dog Distance
题目传送门 题意:两只狗在折线上跑,速度未知,同时出发,同时达到.问跑的过程中,两狗的最大距离和最小距离的差 分析:训练指南P261,考虑相对运动,设A静止不动,B相对A运动,相对的运动向量:Vb - ...
- UVa 11796 计算几何
题目链接:http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem& ...
- UVA 10140 - Prime Distance(数论)
10140 - Prime Distance 题目链接 题意:求[l,r]区间内近期和最远的素数对. 思路:素数打表,打到sqrt(Max)就可以,然后利用大的表去筛素数.因为[l, r]最多100W ...
- UVA 11437 - Triangle Fun 向量几何
http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&p ...
- UVA 11796
题意: 有两个狗, 按照 多边形跑,不知道两条狗的速度,但是狗是同时出发,同时到达终点的 输出两条狗的 最大相距距离 - 最小相距距离: 思路 : 用物理的相对运动来计算, 每次只计算 两条狗的直线 ...
随机推荐
- [XML] C#XMLProcess操作Xml文档的帮助类 (转载)
点击下载 XMLProcess.rar 主要功能如下所示 看下面代码吧 /// <summary> /// 类说明:XMLProcess /// 编 码 人:苏飞 /// 联系方式:361 ...
- DNS(域名系统)域名解析设置
DNS(Domain Name System,域名系统), 因特网上作为域名和IP地址相互映射的一个分布式数据库,能够使用户更方便的访问互联网,而不用去记住能够被机器直接读取的IP数串.通过主机名,最 ...
- Shell编程之Shift的用法
位置参数可以用shift命令左移.比如shift 3表示原来的$4现在变成$1,原来的$5现在变成$2等等,原来的$1.$2.$3丢弃,$0不移动.不带参数的shift命令相当于shift 1. 非常 ...
- C++语言体系设计哲学的一些随想(未完待续)
对于静态类型语言,其本质目标在于恰当地操作数据,得到期望的值.具体而言,需要: (1)定义数据类型 你定义的数据是什么,是整形还是浮点还是字符.该类型的数据可以包含的值的范围是什么. (2)定义操作的 ...
- HDU1862EXCEL排序
其实最近都没有兴趣做排序题目,因为我觉得纯粹排序对我而言进步不大,但是舍友TLE了,叫我试一试. 整道题的思路很简单啦,我用的是快排,比较的原则也给得很清楚,不必多言,我没有用stdlib的快排,也没 ...
- ACM HDU 2044 一只小蜜蜂
Problem Description 有一只经过训练的蜜蜂只能爬向右侧相邻的蜂房,不能反向爬行.请编程计算蜜蜂从蜂房a爬到蜂房b的可能路线数. 其中,蜂房的结构如下所示. Input 输入数据的第一 ...
- shell命令:echo命令详解
功能说明:显示文字. 语 法:echo [-ne][字符串] / echo [--help][--version] 补充说明:echo会将输入的字符串送往标准输出.输出的字符串间以空白字符隔开, 并在 ...
- 在win10 64位下编译,提示[C++ Error] E2075 Incorrect project override option: (x86)\borland\cbuilder6\lib\vcl60.csm
options->compiler 右边有个file name 改下就好了从$(BCB)\lib\vcl60.csm 改为c:\PROGRA~1\borland\CBUILD~1\lib\vc ...
- GoogleCode新手教程
GoogleCode页面介绍 Project Home 首先显示的是project home,页面左边的是这个项目的介绍,右边的License是说明使用的是什么开源协议,Labels是标签的意思,就是 ...
- ubuntu下Qt之android环境配置以及一些常见问题解决
准备材料有: 1. qt for android 5.×版本,下载地址如下,可以选择一个合适自己机器型号的版本进行下载. 地址:http://www.qt.io/download-open-sourc ...