题目:给定一个起点(xw1, yw1),直线经过(xw2, yw2),速度为vw无限运动的点,还有一个起点(xt1, yt1),终点(xt2, yt2),并且在以vt速度在两者往返运动,求两者在运动中的最近距离。。如果小于给定的dl,输出Dangerous,大于du输出Miss,否则输出perfect。。

思路:

ACM2008北京赛区的计算几何题,也是dyf神犇violet系列的一道题。。

思路不是很难,以xw点为参考系,那么题目就变成了求某个点及一些折线的最近距离。。

而且这些折线可以分成两组平行线段,每组可以分别求。

至于怎么求,可以用dyf神犇的数学方法。。(可能我太弱了,写完后一直错挑了半天就直接弃疗了)

我最后用的是直接三分线段,写起来好写一点。。

有什么不明白的可以看dyf博客。。写的很清楚。。

code:

 #include<cstdio>
#include<iostream>
#include<cstring>
#include<cstdlib>
#include<cmath>
#include<algorithm>
#include<string>
#include<map>
#include<set>
#include<vector>
#include<queue>
#include<stack>
#include<ctime>
#include<utility>
#define M0(x) memset(x, 0, sizeof(x))
#define eps 1e-8
#define pi acos(-1.0)
using namespace std;
inline int sgn(const double& x){
return (x > eps) - (x < -eps);
}
struct point{
double x, y;
point(){}
point(double _x, double _y):x(_x), y(_y){}
void input(){
scanf("%lf%lf", &x, &y);
}
double len()const{
return sqrt(x * x + y * y);
}
point trunc(double l)const{
double r = l / len();
return point(r * x, r * y);
}
point rotate_left()const{
return point(-y, x);
}
point operator-(const point& p1)const{
return point(x - p1.x, y - p1.y);
}
point operator+(const point& p1)const{
return point(x + p1.x, y + p1.y);
}
bool operator==(const point& p1)const{
return sgn(x - p1.x) == && sgn(y - p1.y) == ;
}
double operator*(const point& p1)const{
return x * p1.y - y * p1.x;
}
double operator^(const point& p1)const{
return x * p1.x + y * p1.y;
}
point operator*(const double& l) const{
return point(x *l , y * l);
}
void out(){
printf("%.2f %.2f\n", x, y);
}
} p[], p2[], v[], zero(, );
double di, du, vnow; double get_distance(const point &p, const point &p1, const point &p2){
if (sgn((p2 - p1) ^ (p - p1)) <= ) return (p - p1).len();
if (sgn((p1 - p2) ^ (p - p2)) <= ) return (p - p2).len();
return fabs((p1 - p) * (p2 - p)) / (p1 - p2).len();
} void init(){
p2[].input(), scanf("%lf", &vnow);
v[] =(p2[]-p[]).trunc(vnow);
p[].input(), p2[].input(), scanf("%lf", &vnow);
v[] = (p2[] - p[]).trunc(vnow);
p[] = p[] - p[], p2[] = p2[] - p[];
scanf("%lf%lf", &di, &du);
} double gao(const point& p0,const point& p1, const point& p2){
int l = , r = 0x3fffffff, ui, l1, r1;
point v = p2 - p0;
point p00, p11;
double dis1, dis2, ans = 1e20;
while (l + < r){
if (l + >= r){
ans = min(ans, get_distance(zero, p0 + v * l, p1 + v * l));
ans = min(ans, get_distance(zero, p0 + v * r, p1 + v * r));
if (l + == r)
ans = min(ans, get_distance(zero, p0 + v * (l+), p1 + v * (l+)));
break;
}
ui = (r - l + ) / ;
l1 = l + ui, r1 = r - ui;
dis1 = get_distance(zero, p0 + v * l1, p1 + v * l1);
dis2 = get_distance(zero, p0 + v * r1, p1 + v * r1);
if (dis1 < dis2) r = r1;
else l = l1; }
return ans;
} void solve(){
point v1 = v[] - v[], v2 = (v[] + v[]) * (-);
double t = (p2[] - p[]).len() / vnow;
point p0 = p[], p1 = p0 + v1 * t, p3 = p1 + v2 * t, p4 = p3 + v1 * t;
// p0.out(), p1.out(), p3.out(), p4.out();
double ans = gao(p0, p1, p3);
ans = min(gao(p1, p3, p4), ans);
if (ans < di - eps) puts("Dangerous");
else if (ans > du + eps) puts("Miss");
else puts("Perfect");
} int main(){
while (scanf("%lf%lf", &p[].x, &p[].y) != EOF){
init();
solve();
}
return ;
}

poj3924的更多相关文章

随机推荐

  1. 优化myeclipse启动速度以及解决内存不足问题

    解决myeclipse内存不足问题: 使用 MyEclipse 开发项目后,随着项目文件的增多,以及运行时间的增加,实际上 MyEclipse 所消耗的内存是会一直增大的,有的时候会出现 MyEcli ...

  2. docker 运行 elasticsearch + kibana

    一.elasticsearch的安装 1.从官网上拉取 elasticsearch 的镜像 docker pull elasticsearch:5.6.11docker images 2.运行容器 m ...

  3. Python.tornado.2.tornado.options

    记录Tornado-4.0.2源码的阅读,学习,分析 options.py 1. imports 部分 1.1 __future__ from __future__ import absolute_i ...

  4. 洛谷2971 [USACO10HOL]牛的政治Cow Politics

    原题链接 假设只有一个政党,那么这题就退化成求树的直径的问题了,所以我们可以从此联想至\(k\)个政党的情况. 先处理出每个政党的最大深度,然后枚举每个政党的其它点,通过\(LCA\)计算长度取\(\ ...

  5. [转]11种常见sqlmap使用方法详解

    sqlmap也是渗透中常用的一个注入工具,其实在注入工具方面,一个sqlmap就足够用了,只要你用的熟,秒杀各种工具,只是一个便捷性问题,sql注入另一方面就是手工党了,这个就另当别论了.今天把我一直 ...

  6. Java学习笔记:多线程(一)

    Java中线程的五种状态: 新建状态(New) 就绪状态(Runnable) 运行状态(Running) 阻塞状态(Blocked) 凋亡状态(Dead) 其中阻塞状态(Blocked)又分为三种: ...

  7. Spring配置ArgumentResolver,统一进行session鉴定

    一.编写WebMvcConfig配置类: 重写addArgumentResolvers方法,将解析类加入 @Configuration public class WebConfig extends W ...

  8. NOIP水题测试(2017082401)

    哈,水题测试又来了! 上次的水题简单吧! 答案是以单题形式发布的(旅行家的预算随后发布). 下面来看今天的题,还是水题. 时间限制:5小时 题目一:看上去就很水 题目二:比上面一题还水 题目三:数的划 ...

  9. (3)The critical role librarians play in the opioid crisis

    https://www.ted.com/talks/chera_kowalski_the_critical_role_librarians_play_in_the_opioid_crisis 00:1 ...

  10. Github上下载某一个文件夹

    1.安装svn sudo apt-get install subversion 2.修改下载文件夹的链接 例如,https://github.com/a***b/learn/tree/master/m ...