题目:给定一个起点(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. UOJ 274 温暖会指引我们前进 - LCT

    Solution 更新掉路径上温暖度最小的边就可以了~ Code #include<cstdio> #include<cstring> #include<algorith ...

  2. 201621123008 《Java程序设计》第13周学习总结

    1. 本周学习总结 以你喜欢的方式(思维导图.OneNote或其他)归纳总结多网络相关内容. 2. 为你的系统增加网络功能(购物车.图书馆管理.斗地主等)-分组完成 为了让你的系统可以被多个用户通过网 ...

  3. Python压缩文件夹 tar.gz .zip

    打包压缩生成 XXX.tar.gz 文件 import os import tarfile if os.path.exists(outputFileName): with tarfile.open(o ...

  4. nginx指令中的优化(配置文件)

    nginx指令中的优化(配置文件)worker_processes 8; nginx进程数,建议按照cpu数目来指定,一般为它的倍数.worker_cpu_affinity 00000001 0000 ...

  5. IOS语法

    2017-07-15 NSDictionary里要用到的类型转换   [NSNumber numberWithInt: 89] 2017-12-10 定义一个Block的写法 typedef void ...

  6. jquery plugin 之 form表单验证插件

    基于h5表单验证系统.扩展了对easyui组件的支持 先上图: 提示样式用到了伪对象的 {content: attr(xxx)}函数方法,实现提示信息能动态切换. 1.关键属性说明: type: 表单 ...

  7. 《MinDoc 接口文档在线管理系统》

    项目简介 MinDoc 是一款针对IT团队开发的简单好用的文档管理系统. MinDoc 的前身是 SmartWiki 文档系统.SmartWiki 是基于 PHP 框架 laravel 开发的一款文档 ...

  8. UDDI

    什么是 UDDI? UDDI 是一个独立于平台的框架,用于通过使用 Internet 来描述服务,发现企业,并对企业服务进行集成. UDDI 指的是通用描述.发现与集成服务 UDDI 是一种用于存储有 ...

  9. 24、JSON与OC互相转化

    一. JSON: 1. 01.JSON是一种轻量级的数据格式,一般用于数据交互 02.服务器返回给客户端的数据,一般都是JSON格式活着XML格式(文件下载除外) JSON的格式很像OC中的字典和数组 ...

  10. 824. Goat Latin

    class Solution { public: string toGoatLatin(string S) { S.push_back(' '); //add a space that the loo ...