链接:http://www.rqnoj.cn/problem/86

思路:单源点最短路

建图:首先根据父子关系连双向边,边权是距离/速度;再根据跳跃关系连单向边,边权是自由落体的时间(注意自由下落是一个匀加速过程,若中途停下再跳一定没有直接跳优)。

我的实现:

  1 #include <iostream>
2 #include <cstdio>
3 #include <cstring>
4 #include <cmath>
5 #include <algorithm>
6 #include <queue>
7 using namespace std;
8 #define MaxN 120
9 #define MaxM 320
10 #define INF 100000
11 struct P
12 {
13 int v,x,y;
14 }Point[MaxN];
15 struct node
16 {
17 int v;
18 double dist;
19 node *next;
20 };
21 node Edge[MaxM];
22 node *cnt=&Edge[0];
23 node *adj[MaxN];
24 double Dist[MaxN];
25 int N,V;
26 inline void Get_int(int &Ret)
27 {
28 char ch;
29 bool flag=false;
30 for(;ch=getchar(),ch<'0'||ch>'9';)
31 if(ch=='-')
32 flag=true;
33 for(Ret=ch-'0';ch=getchar(),ch>='0'&&ch<='9';Ret=Ret*10+ch-'0');
34 flag&&(Ret=-Ret);
35 }
36 inline double Dis(int a,int b)
37 {
38 double dx=(double)(Point[a].x-Point[b].x);
39 double dy=(double)(Point[a].y-Point[b].y);
40 return sqrt(dx*dx+dy*dy);
41 }
42 inline void Addedge(int u,int v,double w)
43 {
44 node *p=++cnt;
45 p->v=v;
46 p->dist=w;
47 p->next=adj[u];
48 adj[u]=p;
49 }
50 bool Cmp(P a,P b)
51 {
52 return ((a.x<b.x)||(a.x==b.x&&a.y<b.y));
53 }
54 inline void Read_Build()
55 {
56 Get_int(N); Get_int(V);
57 int i,j,pos,fa;
58 double T;
59 for(i=1;i<=N;++i)
60 {
61 Get_int(Point[i].x);Get_int(Point[i].y);
62 Point[i].v=i;
63 Get_int(fa);
64 if(!fa) continue;
65 T=Dis(i,fa)/(double)V;
66 Addedge(i,fa,T); Addedge(fa,i,T);
67 }
68 sort(Point+1,Point+N+1,Cmp);
69 for(i=2;i<=N;i++)
70 {
71 if(Point[i].x!=Point[i-1].x)
72 {
73 pos=i;
74 }
75 else
76 {
77 for(j=pos;j<i;j++)
78 {
79 T=sqrt((double)(Point[i].y-Point[j].y)/5.0);
80 Addedge(Point[i].v,Point[j].v,T);
81 }
82 }
83
84 }
85 }
86 struct cmp
87 {
88 bool operator()(node a,node b)
89 {
90 return a.dist>b.dist;
91 }
92 };
93 priority_queue <node, vector<node>, cmp> q;
94 void Dijkstra(int s)
95 {
96 node c,d,*p;
97 int u,v;
98 for(int i=1;i<=N;i++)
99 Dist[i]=INF;
100 Dist[s]=0;
101 c.v=s;c.dist=0;
102 q.push(c);
103 while(!q.empty())
104 {
105 d=q.top();q.pop();
106 u=d.v;
107 for(p=adj[u];p!=NULL;p=p->next)
108 {
109 v=p->v;
110 if(Dist[v]>Dist[u]+p->dist)
111 {
112 Dist[v]=Dist[u]+p->dist;
113 d.v=v;d.dist=Dist[v];
114 q.push(d);
115 }
116 }
117 }
118 }
119 int main()
120 {
121 Read_Build();
122 Dijkstra(1);
123 printf("%.2lf\n",Dist[N]);
124 return 0;
125 }

[题解]RQNOJ PID86 智捅马蜂窝的更多相关文章

  1. rqnoj86 智捅马蜂窝

    题目描述 背景 为了统计小球的方案数,平平已经累坏了.于是,他摘掉了他那800度的眼镜,躺在树下休息. 后来,平平发现树上有一个特别不一样的水果,又累又饿的平平打算去把它摘下来. 题目描述 现在,将大 ...

  2. [题解]RQNOJ PID87 过河

    链接:http://www.rqnoj.cn/problem/87 思路:动态规划 定义f[i][j]表示到达第 i 块给定石头用了 j 块添加石头的最少步数. 转移方程:f[i][j]=min{f[ ...

  3. [题解]RQNOJ PID85 三个袋子

    链接:http://www.rqnoj.cn/problem/85 思路:一个排列问题,递推式很简单,f(n+1)=3*f(n)-1 ,由此可以推出通项公式,f(n)=0.5*3^(n-1)+0.5 ...

  4. [BZOJ1177][Apio2009]Oil

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

  5. DP——由蒟蒻到神犇的进阶之路

    开始更新咯 DP专题[题目来源BZOJ] 一.树形DP 1.bzoj2286消耗战 题解:因为是树形结构,一个点与根节点不联通,删一条边即可, 于是我们就可以简化这棵树,把有用的信息建立一颗虚树,然后 ...

  6. Educational Codeforces Round 10 A. Gabriel and Caterpillar 模拟

    A. Gabriel and Caterpillar 题目连接: http://www.codeforces.com/contest/652/problem/A Description The 9-t ...

  7. 题解-NOI2003 智破连环阵

    题面 NOI2003 智破连环阵 有 \(m\) 个靶子 \((ax_j,ay_j)\) 和 \(n\) 个箭塔 \((bx_i,by_i)\).每个箭塔可以射中距离在 \(k\) 以内的靶子.第 \ ...

  8. 题解【RQNOJ PID497 0/1字串问题】

    \[ \texttt{Description} \] 编程找出符合下列条件的字符串:①字符串中仅包含 0 和 1 两个字符:②字符串的长度为 n :③字符串中不包含连续重复三次的子串. \[ \tex ...

  9. 第三届“传智杯”全国大学生IT技能大赛(初赛A组)题解

    留念 C - 志愿者 排序..按照题目规则说的排就可以.wa了两发我太菜了qwq #include<bits/stdc++.h> using namespace std; const in ...

随机推荐

  1. Java常见对象内存分析

    首先要明确Java内存的个位置上放的是啥 类.对象.实例三者的关系: 1.类:是对象的模板,可以实例化对象.(this不能出现在静态方法中) 2.对象:类的个体. 3.实例:实现的对象. 4.对应的引 ...

  2. 1121day-户别确认

    1.Addinfor.jsp <%@ page language="java" contentType="text/html; charset=UTF-8" ...

  3. AXAJ基础知识学习

    AXAJ基础知识学习 博客首页 Ajax简介 ajxa全称是Asynchronous Javascript And XML ,就是异步的JS 和XML 通过Ajax可以再浏览器中向服务器发送异步请求, ...

  4. Java Selenide 介绍&使用

    目录 Selenide 介绍 官方快速入门 元素定位 元素操作 浏览器操作 断言 常用配置 Selenide 和 Webdriver 对比 Selenide 介绍 Selenide github Se ...

  5. java IO 文件复制代码模型

    package com.xjtu.demo; import java.io.*; public class FileCopy { public static void main(String[] ar ...

  6. DB2重组表失败处理办法

    set integrity for XXX all immediate unchecked reorg table XXX allow no access 如set integrity for a a ...

  7. 新年好 takoyaki,期待再次与你相见

    一.序 今天是中国农历一年的最后一天,往年都叫年三十,今年没有三十,最后一天是二十九.厨房的柴火味.窗外的鞭炮声还有不远处传来的说笑声,一切都是熟悉味道,新年到了,家乡热闹起来了.平常左邻右舍都是看不 ...

  8. Linux 安装和 连接xshell

    一.介绍和安装 /*一.linux:? 为什么要学习它. 常见的操作系统? 1.windows, linux,mac 使用命令行进行操作 Windows cmd Linux 和Mac 中的命令行是 s ...

  9. git命令行-新建分支与已提交分支合并

    例如要将A分支的一个commit合并到B分支: 首先切换到A分支 git checkout A git log 找出要合并的commit ID : 例如 325d41 然后切换到B分支上 git ch ...

  10. springcloud介绍

    1.认识微服务 随着互联网行业的发展,对服务的要求也越来越高,服务架构也从单体架构逐渐演变为现在流行的微服务架构.这些架构之间有怎样的差别呢? 1.0.学习目标 了解微服务架构的优缺点 1.1.单体架 ...