题意:  有两个狗, 按照 多边形跑,不知道两条狗的速度,但是狗是同时出发,同时到达终点的

输出两条狗的 最大相距距离 - 最小相距距离;

思路 : 用物理的相对运动来计算, 每次只计算 两条狗的直线运动, 转折点再额外更新

LRJ 模板大法好 !!!LRJ 模板大法好 !!!!LRJ 模板大法好 !!!!

#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
using namespace std;
const int maxn = ;
const double eps = 1e-; struct Point {
double x , y;
Point (double x = , double y = ) : x(x),y(y) {}
}; typedef Point Vector; int dcmp (double x) { if(fabs(x) < eps) return ; else return x < ? - : ; } Vector operator + (Vector A, Vector B) { return Vector(A.x+B.x,A.y+B.y); }
Vector operator - (Point A, Point 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);
}
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 Angle (Vector A, Vector B) { return acos(Dot(A,B) / Length(A) / Length(B)); }
double Cross (Vector A, Vector B) { return A.x*B.y - A.y*B.x; }
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);
} double MAX,MIN; void UpDate(Point P, Point A, Point B)
{
MIN = min(MIN, DistanceToSegment(P,A,B)); ///当前 和 点 到线段的最小距离
MAX = max(Length(P-A),MAX);
MAX = max(Length(P-B),MAX);
} Point Pa[maxn], Pb[maxn]; int main()
{
int t;
scanf("%d",&t);
for(int kase = ; kase <= t; kase++)
{
int A, B;
scanf("%d %d",&A,&B);
for(int i = ; i < A; ++i) cin >> Pa[i].x >> Pa[i].y;
for(int i = ; i < B; ++i) cin >> Pb[i].x >> Pb[i].y; double LenA = , LenB = ;
for(int i = ; i < A-; ++i) LenA += Length(Pa[i] - Pa[i+]);
for(int i = ; i < B-; ++i) LenB += Length(Pb[i] - Pb[i+]); MAX = -1e9; MIN = 1e9;
int sa = , sb = ; ///下一个转折点
Point Na = Pa[], Nb = Pb[]; /// 起始位置
while(sa < A- && sb < B-)
{
double La = Length(Pa[sa+] - Na); /// a 当前到下一个转折点的长度
double Lb = Length(Pb[sb+] - Nb); /// b ...
double t = min(La / LenA, Lb / LenB); /// 运动的时间
Vector Va = (Pa[sa+] - Na) / La * t * LenA;/// a 的位移量
Vector Vb = (Pb[sb+] - Nb) / Lb * t * LenB;/// b 的位移量
UpDate(Na,Nb,Nb+Vb-Va); /// B相对A 的运动就是 NB + Vb - Va;
Na = Na + Va; /// 更新 a 的当前点
Nb = Nb + Vb;
if(Na == Pa[sa+]) sa++; ///如果到了转折点, sa 下一个转折点更新
if(Nb == Pb[sb+]) sb++;
}
printf("Case %d: %.0lf\n",kase, 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 计算几何

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

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

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

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

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

  5. UVA 11796 - Dog Distance

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

  6. UVA 11796 Dog Distance(向量)

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

  7. UVA 11796 Dog Distance(几何)

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

  8. uva 1354 Mobile Computing ——yhx

    aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAABGcAAANuCAYAAAC7f2QuAAAgAElEQVR4nOy9XUhjWbo3vu72RRgkF5

  9. UVA 10564 Paths through the Hourglass[DP 打印]

    UVA - 10564 Paths through the Hourglass 题意: 要求从第一层走到最下面一层,只能往左下或右下走 问有多少条路径之和刚好等于S? 如果有的话,输出字典序最小的路径 ...

随机推荐

  1. 安装软件出现缺少vcruntime140.dll

    安装VC运行库QQ群:616945527 ->VC目录下

  2. 传入mybatis的xml为Long型时报There is no getter for property named 'VARCHAR' in

    修改前   <insert id="insert" parameterType="com.taotao.pojo.TbContent" >    i ...

  3. 【noip 2015】普及组

    T1.金币 题目链接 #include<cstdio> #include<algorithm> #include<cstring> using namespace ...

  4. Rsync + inotify 实现文件实时同步

    Rsync 用来实现触发式的文件同步. Inotify-tools是一套组件,Linux内核从2.6.13版本开始提供了inotify通知接口,用来监控文件系统的各种变化情况,如文件存取.删除.移动等 ...

  5. 结构体类型struct

    教学视频 定义: struct student{CString name; int num; TCHAR sex; int age; };   //注意有个分号 student zansan = {_ ...

  6. 2.2 if语句

    if判断语句 <1>if判断语句介绍 if语句是用来进行判断的,其使用格式如下: if 要判断的条件: 条件成立时,要做的事情 demo1:(demo的中文意思:演示.案例) age = ...

  7. [C++]PAT乙级1004. 成绩排名 (20/20)

    /* 1004. 成绩排名 (20) 读入n名学生的姓名.学号.成绩,分别输出成绩最高和成绩最低学生的姓名和学号. 输入格式:每个测试输入包含1个测试用例,格式为 第1行:正整数n 第2行:第1个学生 ...

  8. luogu P3726 [AH2017/HNOI2017]抛硬币

    传送门 我是真的弱,看题解都写了半天,,, 这题答案应该是\(\sum_{i=1}^{a}\binom{a}{i}\sum_{j=0}^{min(b,i-1)}\binom{b}{j}\) 上面那个式 ...

  9. @Component注解的解析

    今天在写程序的时候看见一个以前没有见过的注解(@Component),在网上查找过后,经过实践,决定把它记录下来. 1.@controller 控制器(注入服务) 用于标注控制层,相当于struts中 ...

  10. 在eclipse中从cvs下载项目,再部署到tomcat常见错误!

    1.先调出cvs视图 如果cvs插件还未安装,下载一个: 安装cvs插件:将features和pluguns文件夹里面的内容分别复制到eclipse安装路径下面对应的features和pluguns文 ...