UVA 11796
题意: 有两个狗, 按照 多边形跑,不知道两条狗的速度,但是狗是同时出发,同时到达终点的
输出两条狗的 最大相距距离 - 最小相距距离;
思路 : 用物理的相对运动来计算, 每次只计算 两条狗的直线运动, 转折点再额外更新
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的更多相关文章
- ●UVA 11796 Dog Distance
题链: https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem& ...
- UVa 11796 计算几何
题目链接:http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem& ...
- UVA 11796 - Dog Distance 向量的应用
http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&p ...
- 简单几何(相对运动距离最值) UVA 11796 Dog Distance
题目传送门 题意:两只狗在折线上跑,速度未知,同时出发,同时达到.问跑的过程中,两狗的最大距离和最小距离的差 分析:训练指南P261,考虑相对运动,设A静止不动,B相对A运动,相对的运动向量:Vb - ...
- UVA 11796 - Dog Distance
题意 两条狗啊,同时跑,,同时结束,各自跑各自的道路,问跑的过程中,他们最大距离和最小距离的差: 方法 恶心一点就是,最大最小距离的求解方法,假设两只狗都只有一条线段要跑,则可以判定在端点处有最大 ...
- UVA 11796 Dog Distance(向量)
题目链接:http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=31962 [代码] #include<cstdio> # ...
- UVA 11796 Dog Distance(几何)
Dog Distance [题目链接]Dog Distance [题目类型]几何 &题解: 蓝书的题,刘汝佳的代码,学习一下 &代码: // UVa11796 Dog Distance ...
- uva 1354 Mobile Computing ——yhx
aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAABGcAAANuCAYAAAC7f2QuAAAgAElEQVR4nOy9XUhjWbo3vu72RRgkF5
- UVA 10564 Paths through the Hourglass[DP 打印]
UVA - 10564 Paths through the Hourglass 题意: 要求从第一层走到最下面一层,只能往左下或右下走 问有多少条路径之和刚好等于S? 如果有的话,输出字典序最小的路径 ...
随机推荐
- Linux 有用工具
``` 小问题,在此记录一下,有时在shell下执行命令重定向到文件时提示无权限-bash: temp_20181015.log: Permission denied,而且加sudo执行依提示无权限, ...
- vue使用字体图标转码问题
使用iconfont字体之后,出现的是一个方框,而没有出现相应的图标 需要通过String.fromCharCode方法转成指定unicode编码对应的十六进制字符 <div class=&qu ...
- 032、学容器必须懂bridge网络(2019-02-19 周二)
参考https://www.cnblogs.com/CloudMan6/p/7066851.html docker安装时会创建一个名为 docker0 的linuxbridge.如果不指定 --n ...
- Docker-01 无人值守升级 CentOS 6.x 系统内核到 3.10.x 长期支持版
#!/bin/bash # # 无人值守升级 CentOS .x 系统内核到 3.10.x 长期支持版 # # # .检查操作系统是否为 CentOS .x # cat /etc/centos-rel ...
- tomcat cluster session同步时保存map数据遇到的问题
Tomcat Cluster官网:https://tomcat.apache.org/tomcat-7.0-doc/cluster-howto.html(tomcat7.0) 场景: tomcat1 ...
- adb.exe已停止工作
提示adb.exe错误,我电脑上没有安装豌豆荚,也没运行其它应用,最后发现是360杀毒软件导致的,进程中关掉360Mobile即可.
- GCC编译器原理(二)------编译原理一:ELF文件(2)
四. ELF 文件格式分析 ELF文件(目标文件)格式主要四种: 可重定向文件: 文件保存着代码和适当的数据,用来和其他的目标文件一起来创建一个可执行文件或者是一个共享目标文件.(目标文件或者静态库文 ...
- 【bzoj 1143】[CTSC2008]祭祀river
Description 在遥远的东方,有一个神秘的民族,自称Y族.他们世代居住在水面上,奉龙王为神.每逢重大庆典, Y族都会在水面上举办盛大的祭祀活动.我们可以把Y族居住地水系看成一个由岔口和河道组成 ...
- pyqt5-QWidget-窗口状态(最大化最小化等)
setWindowState(state) #设置窗口状态 Qt.WindowNoState 无状态-正常状态 Qt.WindowMinimized 最小化 Qt.Wind ...
- bus实现兄弟组件传值
传递的地方:两个组件都要引入这个公共的bus中转函数 Bus.js文件相当于一个公共的对象: 传递的文件中写入这个方法: 兄弟组件通过点击事件输出参数,需要的组件来接收传递过来的参数: