简单几何(相对运动距离最值) UVA 11796 Dog Distance
题意:两只狗在折线上跑,速度未知,同时出发,同时达到。问跑的过程中,两狗的最大距离和最小距离的差
分析:训练指南P261,考虑相对运动,设A静止不动,B相对A运动,相对的运动向量:Vb - Va(可以理解为速度矢量),那么就是pa到线段pb-pb+Vb-Va的距离最值
/************************************************
* Author :Running_Time
* Created Time :2015/10/22 星期四 10:21:19
* File Name :UVA_11796.cpp
************************************************/ #include <cstdio>
#include <algorithm>
#include <iostream>
#include <sstream>
#include <cstring>
#include <cmath>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <stack>
#include <list>
#include <map>
#include <set>
#include <bitset>
#include <cstdlib>
#include <ctime>
using namespace std; #define lson l, mid, rt << 1
#define rson mid + 1, r, rt << 1 | 1
typedef long long ll;
const int N = 55 + 10;
const int INF = 0x3f3f3f3f;
const int MOD = 1e9 + 7;
const double EPS = 1e-10;
struct Point {
double x, y;
Point (double x=0, double y=0) : x (x), y (y) {}
};
typedef Point Vector;
double dot(Vector A, Vector B) {
return A.x * B.x + A.y * B.y;
}
double cross(Vector A, Vector B) {
return A.x * B.y - A.y * B.x;
}
int dcmp(double x) {
if (fabs (x) < EPS) return 0;
else return x < 0 ? -1 : 1;
}
Vector operator + (Vector A, Vector B) {
return Vector (A.x + B.x, A.y + B.y);
}
Vector operator - (Vector A, Vector 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) == 0 && dcmp (a.y - b.y) == 0;
}
double length(Vector A) {
return sqrt (dot (A, A));
}
double dis_to_seg(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)) < 0) return length (V2);
else if (dcmp (dot (V1, V3)) > 0) return length (V3);
else return fabs (cross (V1, V2)) / length (V1);
}
Point A[N], B[N];
double mx, mn; void updata(Point p, Point a, Point b) {
mn = min (mn, dis_to_seg (p, a, b));
mx = max (mx, max (length (p - a), length (p - b)));
} int main(void) {
int T, cas = 0; scanf ("%d", &T);
while (T--) {
int na, nb; scanf ("%d%d", &na, &nb);
for (int i=0; i<na; ++i) scanf ("%lf%lf", &A[i].x, &A[i].y);
for (int i=0; i<nb; ++i) scanf ("%lf%lf", &B[i].x, &B[i].y);
double lena = 0, lenb = 0;
for (int i=0; i<na-1; ++i) lena += length (A[i+1] - A[i]);
for (int i=0; i<nb-1; ++i) lenb += length (B[i+1] - B[i]);
int sa = 0, sb = 0;
mx = -1e9; mn = 1e9;
Point pa = A[0], pb = B[0];
while (sa < na - 1 && sb < nb - 1) {
double la = length (A[sa+1] - pa);
double lb = length (B[sb+1] - pb);
double tim = min (la / lena, lb / lenb);
Vector Va = (A[sa+1] - pa) / la * tim * lena;
Vector Vb = (B[sb+1] - pb) / lb * tim * lenb;
updata (pa, pb, pb + Vb - Va);
pa = pa + Va;
pb = pb + Vb;
if (pa == A[sa+1]) sa++;
if (pb == B[sb+1]) sb++;
}
printf ("Case %d: %.0f\n", ++cas, mx - mn);
} return 0;
}
简单几何(相对运动距离最值) UVA 11796 Dog Distance的更多相关文章
- UVA 11796 Dog Distance(几何)
Dog Distance [题目链接]Dog Distance [题目类型]几何 &题解: 蓝书的题,刘汝佳的代码,学习一下 &代码: // UVa11796 Dog Distance ...
- ●UVA 11796 Dog Distance
题链: https://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
题意 两条狗啊,同时跑,,同时结束,各自跑各自的道路,问跑的过程中,他们最大距离和最小距离的差: 方法 恶心一点就是,最大最小距离的求解方法,假设两只狗都只有一条线段要跑,则可以判定在端点处有最大 ...
- UVA 11796 Dog Distance(向量)
题目链接:http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=31962 [代码] #include<cstdio> # ...
- Python下opencv使用笔记(二)(简单几何图像绘制)
简单几何图像一般包含点.直线.矩阵.圆.椭圆.多边形等等.首先认识一下opencv对像素点的定义. 图像的一个像素点有1或者3个值.对灰度图像有一个灰度值,对彩色图像有3个值组成一个像素值.他们表现出 ...
- 几何不能具有Z值
ArcEngine 复制要素Geometry时,产生 几何不能具有Z值 的异常 解决方法:http://forums.esri.com/Thread.asp?c=159&f=1707& ...
- Codeforces 935 简单几何求圆心 DP快速幂求与逆元
A #include <bits/stdc++.h> #define PI acos(-1.0) #define mem(a,b) memset((a),b,sizeof(a)) #def ...
- 简单几何(数学公式+凸包) UVA 11168 Airport
题目传送门 题意:找一条直线,使得其余的点都在直线的同一侧,而且使得到直线的平均距离最短. 分析:训练指南P274,先求凸包,如果每条边都算一边的话,是O (n ^ 2),然而根据公式知直线一般式为A ...
随机推荐
- 微信发明人竟是他!也是WeChat/Line/WhatsApp的发明者
赵建文,很多人不知道他是谁:说到微信大家都耳熟能详吧?没错,他就是初始微信发明人,同时也是WeChat/Line/WhatsApp的发明者!正是他的专利<一种基于或囊括手机电话本的即时通讯方法和 ...
- 微信公开课发布微信官方教程:教你用好微信JS-SDK接口
微信公众平台开放JS-SDK(微信内网页开发工具包),说明文档已经有相关使用方法和示例了,很多同学觉得不是很直观,为此微信公开课发布微信官方教程:教你用好微信JS-SDK接口. 1.分享类接口:支持获 ...
- 虚拟机里面安装Openfiler 2.99
简介 Openfiler 由rPath Linux驱动,它是一个基于浏览器的免费网络存储管理实用程序,可以在单一框架中提供基于文件的网络连接存储 (NAS) 和基于块的存储区域网 (SAN).Open ...
- poj2993 翻转2996
Emag eht htiw Em Pleh Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 2944 Accepted: ...
- Textview下划线注册用户跳转实现
在xml中: <TextView android:id="@+id/textView_regtext" android:layout_width="wrap_con ...
- django-cms 代码研究(五)深入(代码结构)
前言: 前戏已经做得比较充分了,下面我们开始步入正题. 代码结构: cms |--admin (猜测是admin界面的二次开发和改良) |--cache (猜测是缓存机制的处理) |--extensi ...
- 破解php-screw加密过的文件有效方法
今天终于搞定更改过密钥的php-screw解密问题,乐呵一下! 改进下 这样就可以解密任何加密过的PHP源码(包括更改过密钥的),解密的原理稍后具体列出,先说下如何加密 列出之前写使用php scre ...
- load url from future 解释
利用url 标签之后,不管urlpatterns里的某个地址叫法怎么改变,Templates里的地址都不用修改了.在模版中调用url标签的时候,需要:{% load url from future % ...
- 【转】PowerDesigner使用方法小结
本文转自:http://www.cnblogs.com/afarmer/archive/2012/11/05/2755327.html PowerDesigner多用来进行数据库模型设计,具有SQL语 ...
- iOS 中添加lib型target库的依赖问题
今天在编码时遇到一个问题,总提示我找不到系统库文件. 我的项目结构类似下图 在TestLib中有引用CoreLocation库的类.但是CoreLocation库需要加在PhotoInfoDemo对象 ...