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

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

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

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. IO流--字符流与字节流--File类常用功能

    IO流的常用方法: 1: 文件的读取和写入图解: 2:字节流: 读写文件的方法: 一般效率读取: 读取文件:        FileInputStream(); 写数据:            Fil ...

  2. 未启用当前数据库的 SQL Server Service Broker,因此查询通知不受支持。如果希望使用通知,请为此数据库启用 Service Broker

    昨晚遇到的这个问题,也知道Notifications service依赖底层的Service broker的.本以为只需要执行以下脚本对数据库启用Service broker即可. alter dat ...

  3. 解析ArcGis的标注(一)——先看看分数式、假分数式标注是怎样实现的

    该“标注”系列博文的标注引擎使用“标准标注引擎(standard label engine)”,这个概念如不知道,可不理会,ArcGis默认标注引擎就是它. ArcGis的标注表达式支持VBScrip ...

  4. 建立爬虫代理IP池

    单线程构建爬虫代理IP池 #!/usr/bin/python3.5 # -*- coding:utf-8 -*- import time import tempfile from lxml impor ...

  5. SpringBoot系列: Java应用程序传参和SpringBoot参数文件

    ===========================向java 程序传参的几种形式:===========================1. 使用 OS 环境变量. 这个不推荐. 2. 使用JVM ...

  6. SSH免费登录

    SSH免费登录很简单,如果有用过git的就更简单了 只需要一下两步操作就OK: 1.生成公钥和私钥,在linx上生成公钥和私钥,执行:ssh-keygen 2.执行ssh-copy-id +ip 例如 ...

  7. floyd求最小环

    ;i<=n;i++) ;j<=n;j++) g[i][j]=g[j][i]=dis[i][j]=dis[j][i]=inf; ;i<=m;i++){ int u,v,w;scanf( ...

  8. AD软件使用心得

    1.在更新原理图之前一定要标记所有器件,否则无法生成PCB器件. 2.学会用sch list网表来批量修改器件名称 3.布线的面

  9. Docker(一)基本概念

    摘自 https://mp.weixin.qq.com/s/mcIMBMNMrFD9OE56iujhXQ 一.容器和虚拟机的比较 1.虚拟机 对于以前熟悉的虚拟机,我们需要模拟操作系统和硬件.虚拟机一 ...

  10. bzoj3262: 陌上花开(CDQ+树状数组处理三维偏序问题)

    题目链接:https://www.lydsy.com/JudgeOnline/problem.php?id=3262 题目大意:中文题目 具体思路:CDQ可以处理的问题,一共有三维空间,对于第一维我们 ...