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? 如果有的话,输出字典序最小的路径 ...
随机推荐
- 历史SQL语句之一
注释:查询该课程表下,所有的课程以及课程观看的人数统计 SELECT ml.`name` as lessonName,ml.category,ml.deleted,ml.teacherName, ml ...
- [Asp.Net MVC4]验证用户登录实现
最近我们要做一个仿sina的微博,碰巧的是我最近在学习mvc,就想用mvc技术实现这个项目. 既然是微博,那不用想也应该知道肯定要有用户登陆,但是和常规的asp.net登陆又不一样,以下是我一下午+一 ...
- Native APP ,Web APP,Hybrid APP三者对比
Native APP Native APP 指的是原生程序(Android.iOS.WP),一般依托于操作系统,有很强的交互,可拓展性强,需要用户下载安装使用,是一个完整的App. 原生应用程序是某一 ...
- Objects类的静态方法
提供了几个静态方法,比如进行对象之间的比较等,而又因为Object是任何对象的超类,因为每个对象都可以调用这几个方法. 1.equals方法 可以防止空指针异常 String s1 = null; S ...
- Git 命令解释优秀博文转摘
git rebase http://blog.csdn.net/hudashi/article/details/7664631 git merge git reset http://www.cnblo ...
- ****** 四十九 ******、软设笔记【UML分析和意义】-建模的意义,UML的特点、结构,用例图
UML UML又称同一建模语言或标准建模语言,是一个支持模型化和软件系统开发的图形化语言,它的作用域不仅支持面向对象的分析与设计,还支持从需求分析开始的软件开发的全过程. 建模的意义: 模型是对现实的 ...
- oracle 任务备份
@echo offset hour=%time:~,2%if "%time:~,1%"==" " set hour=0%time:~1,1%set temp=% ...
- Java EE之Request部分方法使用示例
Description: ApplicationProjectName:MedicineMs login.jsp[action:login|method:get] to loginServlet Ou ...
- react 在IE9下input标签使用e.target.value取值失败
在react项目开发中,input标签使用onChange方法获取输入值改变state: <input type="text" id="redeemNum" ...
- ubuntu安装GBK编码
1 添加GBK编码 sudo vim /var/lib/locales/supported.d/local en_US.UTF-8 UTF-8 zh_CN.UTF-8 UTF-8 zh_CN.GBK ...