题链:

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

题解:

计算几何,骚操作
对于简单情况,即两只狗的路线均为一条线段,
可以从相对运动的角度出发,考虑一直狗不动,另一只狗在运动。
而由于两只狗此时都在做匀速直线运动,所以在那只不懂的狗看来,另一直狗也在匀速直线前行。(物理老师:速度的矢量和!)
所以这个简单情况下,问题就变为了求一个点到一条线段的最短和最长距离。

而本题中虽然路线为多条折线,但仍然可以根据拐点把路线拆为一个个的简单情况,进而即可求解。

代码:

#include<cmath>
#include<cstdio>
#include<cstring>
#include<iostream>
#define MAXN 60
using namespace std;
const double eps=1e-8;
struct Point{
double x,y;
Point(double _x=0,double _y=0):x(_x),y(_y){}
void Read(){scanf("%lf%lf",&x,&y);}
};
int sign(double x){
if(fabs(x)<=eps) return 0;
return x<0?-1:1;
}
typedef Point Vector;
bool operator == (Point A,Point B){return sign(A.x-B.x)==0&&sign(A.y-B.y)==0;}
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);}
double operator ^ (Vector A,Vector B){return A.x*B.y-A.y*B.x;}
double operator * (Vector A,Vector B){return A.x*B.x+A.y*B.y;}
Vector Va,Vb;
Point Da[MAXN],Db[MAXN],Pa,Pb;
int T,Na,Nb,ia,ib;
double minans,maxans,La,Lb,Lena,Lenb,tim;
double GL(Vector A){//Get_Length
return sqrt(A*A);
}
double DTS(Point P,Point a1,Point a2){//Distance_To_Segment
static Vector v1,v2,v3;
v1=a2-a1; v2=P-a1; v3=P-a2;
if(a1==a2) return GL(v2);
if(sign(v1*v2)<0) return GL(v2);
if(sign(v1*v3)>0) return GL(v3);
return fabs(v2^v3)/GL(v1);
}
void contribution(Point P,Point a1,Point a2){
minans=min(minans,DTS(P,a1,a2));
maxans=max(maxans,GL(P-a1));
maxans=max(maxans,GL(P-a2));
}
int main(){
freopen("/home/noilinux/Documents/模块学习/计算几何/11796.in","r",stdin);
scanf("%d",&T);
for(int t=1;t<=T;t++){
scanf("%d%d",&Na,&Nb);
for(int i=1;i<=Na;i++) Da[i].Read();
for(int i=1;i<=Nb;i++) Db[i].Read();
Lena=Lenb=0; minans=1e9; maxans=-1e9;
for(int i=1;i<Na;i++) Lena+=GL(Da[i+1]-Da[i]);
for(int i=1;i<Nb;i++) Lenb+=GL(Db[i+1]-Db[i]);
ia=1,ib=1; Pa=Da[1],Pb=Db[1];
while(ia<Na&&ib<Nb){
La=GL(Da[ia+1]-Pa);
Lb=GL(Db[ib+1]-Pb);
tim=min(La/Lena,Lb/Lenb);
Va=(Da[ia+1]-Pa)/La*tim*Lena;
Vb=(Db[ib+1]-Pb)/Lb*tim*Lenb;
contribution(Pa,Pb,Pb+Vb-Va);
Pa=Pa+Va; Pb=Pb+Vb;
if(Pa==Da[ia+1]) ia++;
if(Pb==Db[ib+1]) ib++;
}
printf("Case %d: %.0lf\n",t,maxans-minans);
}
return 0;
}

  

●UVA 11796 Dog Distance的更多相关文章

  1. UVA 11796 Dog Distance(几何)

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

  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 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 11796

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

  9. UVA11796 Dog Distance

    题意 PDF 分析 问题可以转化为小问题,即两条狗分别在线段上运动. 然后用相对运动知识可以认为甲不动,乙在线段上运动. 小问题就转化为点到线段的最小或最大距离. 时间复杂度\(O(I \times ...

随机推荐

  1. 团队作业8——测试与发布(Beta阶段)

    Deadline: 2017-12-17 23:00PM,以博客发表日期为准.   评分基准: 按时交 - 有分,检查的项目包括后文的三个方面 测试报告 发布说明 展示博客(单独一篇博客) 晚交 - ...

  2. mobiscroll2.5.4 日期组件

    <script type="text/javascript"> function setCss(o) { $('input:jqmData(role="dat ...

  3. 第一部分 linux系统命令

    一.linux系统命令 pwd 当前目录位置 / 根目录 cd (change direcory) cd ..返回上一层目录 ls 显示当前目录下文件 ls -l 显示目录下详细文件信息 ls -lh ...

  4. verilog学习笔记(2)_一个小module及其tb

    module-ex_cnt module ex_cnt( input wire sclk, input wire rst_n, output wire[9:0] cnt ); reg [9:0] cn ...

  5. MMA8451重力加速度计通过写内部校准寄存器进行校准

    |版权声明:本文为博主原创文章,未经博主允许不得转载. AN4069应用笔记中提到MMA8451的三个轴重力校准有两种方法, 第一种方法是简易校准,将贴有MMA8451的设备整体,Z轴正面朝上放在校准 ...

  6. js判断操作系统windows,ios,android(笔记)

    使用JS判断用户使用的系统是利用浏览器的userAgent. navigator.userAgent:userAgent 获取了浏览器用于 HTTP 请求的用户代理头的值. navigator.pla ...

  7. Win10下, TortoiseGit安装及配合Gitee使用完整版

    Windows10下, TortoiseGit的安装及使用, 并配合Gitee码云使用! 1) 安装TortoiseGit 官网, 32位, 64位, 自选 https://tortoisegit.o ...

  8. kali linux 2.0 web 渗透测试 电子书

    原创 2017-05-31 玄魂工作室 玄魂工作室 打起精神,重新开启订阅号的原创文章写作工作,但是需要点时间,请耐心等待. 求资料的同学,没有及时回复的,请再次留言,我会尽快处理.今天分享两本电子书 ...

  9. C#日志文件

    写日志文件是一个很常用的功能,以前都是别人写好的,直接调用的,近期写了一个小工具,因为比较小,所以懒得引用dll文件了,直接上网找了一个,很方便,现在记录下 public class LogClass ...

  10. C#制作ActiveX插件

    首先新建项目--->类库,取名:ActiveXDemo 右键项目属性:应用属性==>程序集信息=>使程序集Com可见, 生成==>输出==>为com互操作注册 新建接口类 ...