题目传送门

题意:两只狗在折线上跑,速度未知,同时出发,同时达到。问跑的过程中,两狗的最大距离和最小距离的差

分析:训练指南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的更多相关文章

  1. UVA 11796 Dog Distance(几何)

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

  2. ●UVA 11796 Dog Distance

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

  3. UVA 11796 - Dog Distance 向量的应用

    http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&p ...

  4. UVA 11796 - Dog Distance

    题意  两条狗啊,同时跑,,同时结束,各自跑各自的道路,问跑的过程中,他们最大距离和最小距离的差: 方法  恶心一点就是,最大最小距离的求解方法,假设两只狗都只有一条线段要跑,则可以判定在端点处有最大 ...

  5. UVA 11796 Dog Distance(向量)

    题目链接:http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=31962 [代码] #include<cstdio> # ...

  6. Python下opencv使用笔记(二)(简单几何图像绘制)

    简单几何图像一般包含点.直线.矩阵.圆.椭圆.多边形等等.首先认识一下opencv对像素点的定义. 图像的一个像素点有1或者3个值.对灰度图像有一个灰度值,对彩色图像有3个值组成一个像素值.他们表现出 ...

  7. 几何不能具有Z值

    ArcEngine 复制要素Geometry时,产生 几何不能具有Z值 的异常 解决方法:http://forums.esri.com/Thread.asp?c=159&f=1707& ...

  8. Codeforces 935 简单几何求圆心 DP快速幂求与逆元

    A #include <bits/stdc++.h> #define PI acos(-1.0) #define mem(a,b) memset((a),b,sizeof(a)) #def ...

  9. 简单几何(数学公式+凸包) UVA 11168 Airport

    题目传送门 题意:找一条直线,使得其余的点都在直线的同一侧,而且使得到直线的平均距离最短. 分析:训练指南P274,先求凸包,如果每条边都算一边的话,是O (n ^ 2),然而根据公式知直线一般式为A ...

随机推荐

  1. 完美串(区间dp)

    完美串 Description 爱美之心人皆有之,GG也不例外.所以GG他对于完美串有一种热衷的爱.在GG眼中完美串是一个具有无比魅力的01子串.这个子串有之其魅力之处,对它取反后水平翻转,它又和它原 ...

  2. Xcode 4.6.3 Bug - .m 文件不能正常打开,uitableveiwController

    当打开.m文件时尤其是自定义的继承uitableviewcontroler的m 文件.不能滑动,不能正常显示. 解决方法: 用文本编辑器打开这个文件,关闭xcode .然后在继承uitableview ...

  3. cocos基础教程(1)Mac环境下搭建

    下面主要介绍cocos2d-x环境的设置以及android的环境搭建 1.下载cocos2d-x 3.0正式版      http://www.cocos2d-x.org/download 2.下载a ...

  4. Swift Tour 随笔总结 (3)

    关于Optional的Control Flow if let constantName = someOptional { statements } 如果该Optional为nil,则不进入if,否则执 ...

  5. RecContentType有哪些

    HTML  页面text/javascript  `type="text/javascript"` 是比较老的写法IETF 推荐的是 `type="application ...

  6. L17 怎么向应用程序商店提交应用

    原地址:https://developer.apple.com/library/ios/#referencelibrary/GettingStarted/RoadMapiOS/ApplicationD ...

  7. [BZOJ1177][Apio2009]Oil

    [BZOJ1177][Apio2009]Oil 试题描述 采油区域 Siruseri政府决定将石油资源丰富的Navalur省的土地拍卖给私人承包商以建立油井.被拍卖的整块土地为一个矩形区域,被划分为M ...

  8. JAVA接口继承、抽象类等

    1.定义接口 package test.intefaces; public interface TestIntefaceA { void testA(); void testB(); void tes ...

  9. springMVC 上传文件

    spring mvc(注解)上传文件的简单例子,这有几个需要注意的地方1.form的enctype=”multipart/form-data” 这个是上传文件必须的2.applicationConte ...

  10. iOS8 UILocalNotification 和 UIRemoteNotification 使用注意 草稿,正在整理中。。。。

    先说一个关于UILocalNotification的知识点,容易被忘记: Each app on a device is limited to 64 scheduled local notificat ...