根据光路最快原理以及斯涅尔定律,可以得到从定点$P$进入某条直线的最佳入射角。

求出每个端点到每条线段的最佳点,建图求最短路即可。

时间复杂度$O(n^2\log n)$。

#include<cstdio>
#include<cmath>
#include<algorithm>
#include<vector>
#include<queue>
using namespace std;
typedef pair<double,int>PI;
const int N=2100000,M=9100000;
const double eps=1e-6,inf=1e100;
int n,cnt,i,j,g[N],v[M],nxt[M],ed;double w[M],d[N],va,vb,si[2],co[2];
priority_queue<PI,vector<PI>,greater<PI> >q;
inline void add(int x,int y,double z){v[++ed]=y;w[ed]=z;nxt[ed]=g[x];g[x]=ed;}
inline void add2(int x,int y,double z){add(x,y,z),add(y,x,z);}
inline void ext(int x,double y){if(y+eps<d[x])q.push(PI(d[x]=y,x));}
inline int sgn(double x){
if(x>eps)return 1;
if(x<-eps)return -1;
return 0;
}
struct P{
double x,y;
P(){}
P(double _x,double _y){x=_x,y=_y;}
P operator+(P b){return P(x+b.x,y+b.y);}
P operator-(P b){return P(x-b.x,y-b.y);}
P operator*(double b){return P(x*b,y*b);}
P operator/(double b){return P(x/b,y/b);}
double operator*(P b){return x*b.x+y*b.y;}
bool operator==(P b){return !sgn(x-b.x)&&!sgn(y-b.y);}
double len(){return hypot(x,y);}
P rotate(double s,double c){return P(x*c-y*s,x*s+y*c);}
P rot90(){return P(-y,x);}
}a[1010];
struct E{
double x;int y;
E(){}
E(double _x,int _y){x=_x,y=_y;}
}e[2010];
inline bool cmp(const E&a,const E&b){return a.x<b.x;}
inline double cross(P a,P b){return a.x*b.y-a.y*b.x;}
inline bool point_on_segment(P p,P a,P b){
return sgn(cross(b-a,p-a))==0&&sgn((p-a)*(p-b))<=0;
}
inline P line_intersection(P a,P b,P p,P q){
double U=cross(p-a,q-p),D=cross(b-a,q-p);
return a+(b-a)*(U/D);
}
inline void work(int st,int en){
int i,j,m=2;
P A=a[st],B=a[en],C=(B-A).rot90();
e[1]=E(0,st),e[2]=E(C.len(),en);
for(i=0;i<=n;i++)if(i!=st&&i!=en)for(j=0;j<2;j++){
P D=line_intersection(A,B,a[i],a[i]+C.rotate(si[j],co[j]));
if(D==A||D==B)continue;
if(!point_on_segment(D,A,B))continue;
cnt++;
add2(i,cnt,(a[i]-D).len()/vb);
e[++m]=E((D-A).len(),cnt);
}
sort(e+1,e+m+1,cmp);
for(i=1;i<m;i++)add2(e[i].y,e[i+1].y,(e[i+1].x-e[i].x)/va);
}
int main(){
scanf("%d%lf%lf",&n,&va,&vb);
for(i=1;i<=n;i++)scanf("%lf%lf",&a[i].x,&a[i].y);
if(sgn(va-vb)<=0)return printf("%.10f",(a[0]-a[n]).len()/vb),0;
si[0]=vb/va;
co[0]=sqrt(1.0-si[0]*si[0]);
si[1]=-si[0];
co[1]=co[0];
cnt=n;
for(i=0;i<=n;i++)for(j=0;j<i;j++)add2(i,j,(a[i]-a[j]).len()/vb);
for(i=0;i<n;i++)work(i,i+1);
for(i=0;i<=cnt;i++)d[i]=inf;
ext(0,0);
while(!q.empty()){
PI t=q.top();q.pop();
if(t.first-eps>d[t.second])continue;
for(i=g[t.second];i;i=nxt[i])ext(v[i],t.first+w[i]);
}
return printf("%.10f",d[n]),0;
}

  

BZOJ2596 : [Wc2007]疯狂赛车的更多相关文章

  1. bzoj AC倒序

    Search GO 说明:输入题号直接进入相应题目,如需搜索含数字的题目,请在关键词前加单引号 Problem ID Title Source AC Submit Y 1000 A+B Problem ...

  2. FC红白机游戏列表(维基百科)

    1055个fc游戏列表 日文名 中文译名 英文版名 发行日期 发行商 ドンキーコング 大金刚 Donkey Kong 1983年7月15日 任天堂 ドンキーコングJR. 大金刚Jr. Donkey K ...

  3. 【疯狂造轮子-iOS】JSON转Model系列之二

    [疯狂造轮子-iOS]JSON转Model系列之二 本文转载请注明出处 —— polobymulberry-博客园 1. 前言 上一篇<[疯狂造轮子-iOS]JSON转Model系列之一> ...

  4. 【疯狂造轮子-iOS】JSON转Model系列之一

    [疯狂造轮子-iOS]JSON转Model系列之一 本文转载请注明出处 —— polobymulberry-博客园 1. 前言 之前一直看别人的源码,虽然对自己提升比较大,但毕竟不是自己写的,很容易遗 ...

  5. 【腾讯Bugly干货分享】OCS——史上最疯狂的iOS动态化方案

    本文来自于腾讯Bugly公众号(weixinBugly),未经作者同意,请勿转载,原文地址:https://mp.weixin.qq.com/s/zctwM2Wf8c6_sxT_0yZvXg 导语 在 ...

  6. 你真的会玩SQL吗?Case也疯狂

    你真的会玩SQL吗?系列目录 你真的会玩SQL吗?之逻辑查询处理阶段 你真的会玩SQL吗?和平大使 内连接.外连接 你真的会玩SQL吗?三范式.数据完整性 你真的会玩SQL吗?查询指定节点及其所有父节 ...

  7. 0038 Java学习笔记-多线程-传统线程间通信、Condition、阻塞队列、《疯狂Java讲义 第三版》进程间通信示例代码存在的一个问题

    调用同步锁的wait().notify().notifyAll()进行线程通信 看这个经典的存取款问题,要求两个线程存款,两个线程取款,账户里有余额的时候只能取款,没余额的时候只能存款,存取款金额相同 ...

  8. 疯狂Java笔记

    第四章: 4.6深入数组 1.栈内存和堆内存 每个方法都会建立自己的内存栈,在这个方法内定义的变量会逐个放入栈内存里,随着方法的执行结束,这个方法的内存栈也将自然销毁.因此,所有在方法中定义的局部变量 ...

  9. 使用Unity3D的设计思想实现一个简单的C#赛车游戏场景

    最近看了看一个C#游戏开发的公开课,在该公开课中使用面向对象思想与Unity3D游戏开发思想结合的方式,对一个简单的赛车游戏场景进行了实现.原本在C#中很方便地就可以完成的一个小场景,使用Unity3 ...

随机推荐

  1. windows 7 下用git

    参考:http://my.oschina.net/longxuu/blog/141699

  2. 关于HTML或JS加密解密的七种方式

    本文一共介绍了七种方法:   一:最简单的加密解密   二:转义字符""的妙用   三:使用Microsoft出品的脚本编码器Script Encoder来进行编码    (自创简 ...

  3. WebService服务介绍与调用

    一: WebService简介 WebService是一个平台独立的,低耦合的,自包含的.基于可编程的web的应用程序,可使用开放的XML(标准通用标记语言的下的一个子集)标准来描述.发布.发现.协调 ...

  4. vi不保存退出

    To quit the vi editor without saving any changes you've made If you are currently in insert or appen ...

  5. Swap file ".hive-site.xml.swp" already exists

    1.使用命令[hadoop@slaver1 conf]$ ls -la查找出隐藏文件,然后删除报出来的错误文件. [hadoop@slaver1 conf]$ rm -rf .hive-site.xm ...

  6. 盘点那些Vs中常用到的Tab快捷编码

    1.快速声明for循环:for+Tab 2.快速声明Foreach遍历:foreach+Tab 3.快速定义属性:prop+Tab 4.

  7. C#操作windows服务

    本文主要说明了Windows服务的安装.卸载.启动.停止.获取服务安装路径.获取服务状态.检查服务是否存在.获取服务版本. 我们需要引用命名空间using System.Configuration.I ...

  8. Summary of continuous function spaces

    In general differential calculus, we have learned the definitions of function continuity, such as fu ...

  9. 在 Xshell 中 使用 hbase shell 进入后 无法删除 问题

    在 Xshell 中 使用 hbase shell 进入后 无法删除 问题: 在hbase shell下,误输入的指令不能使用backspace和delete删除,使用过的人都知道,这是有多坑,有多苦 ...

  10. python基础——list和tuple(列表和元组)

    1.list的定义,插入insert,append,按位置索引. >>> name = ['Macal','lily','lucy','bob']  --初始化>>> ...