简单几何(相对运动距离最值) 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 ...
随机推荐
- 微信智慧KTV上线 不怕周末订不到包厢了
周末邀三五好友唱唱歌是件惬意的事,可订包厢是个烦心事,总是people mountain people sea,而且价格比平时高出不少.现在好了,微信智慧KTV上线了,将有效解决传统KTV收银时间集中 ...
- Tautology(structure)
Tautology Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 10061 Accepted: 3826 Descri ...
- ABK (枚举)
ABK Accepted : 24 Submit : 176 Time Limit : 1000 MS Memory Limit : 65536 KB 题目描述 ABK是一个比A+B还要简单 ...
- reverse array java
/* package whatever; // don't place package name! */ import java.util.*; import java.lang.*; import ...
- [HDU5015]233 Matrix
[HDU5015]233 Matrix 试题描述 In our daily life we often use 233 to express our feelings. Actually, we ma ...
- hiho一下 第九十六周 数论五·欧拉函数
题目1 : 数论五·欧拉函数 时间限制:10000ms 单点时限:1000ms 内存限制:256MB 描述 小Hi和小Ho有时候会用密码写信来互相联系,他们用了一个很大的数当做密钥.小Hi和小Ho约定 ...
- ZeroMQ(java)中的数据流SessionBase与SocketBase
前面的文章中已经比较的清楚了ZeroMQ(java)中如何在底层处理IO, 通过StreamEngine对象来维护SelectableChannel对象以及IO的事件回调,然后通过Poller对象来维 ...
- linux下用mii-tool和ethtool 查看网线是否正确连接到网卡
输入mii-tool可以查看网线是否连接到网卡#mii-tool eth0: negotiated 100baseTx-FD, link ok 有时驱动可能不支持会出错下列错误#mii-tool SI ...
- 【Python】Django 时间字段 最佳实践
. python datetime from datetime import datetime datetime.now() datetime.utcnow() from datetime impor ...
- kettle转换JavaScript加载外部js文件
日常开发中,时常会出现这样一种情况.有大量的函数是通用的.而每个JavaScript里面写一遍,给维护带来很大的困扰.因而需要将公共的函数写在外部js文件中.这时就需要引入外部的公共文件了.下面是在转 ...