链接: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. 【CSAPP】第三章 程序的机器级表示

    目录 1. 数据的编码与存储 2. 汇编指令 2.1 数据传送指令 访存方式 数据传送指令 入栈出栈 2.2 算术/逻辑指令 2.3 过程控制指令 控制码 比较指令 跳转指令 条件设置指令 3. 程序 ...

  2. C# 实现NPOI的Excel导出

    技术点: 1.自定义attribute属性 2.通过反射取类及其属性的attribute属性值 3.NPOI包常用属性及方法(我也仅仅知道用到过的,陌生的要么见名知意,要么百度查) 实现功能点: Li ...

  3. 五种IO模型(Model)

    目录 一:IO模型简介 1.五种IO Model: 二:五种IO模型简介 1.阻塞IO 2.非阻塞IO 3.多路复用IO 4.信号驱动IO模型 5.异步IO 三:5种I/O模型的比较 一:IO模型简介 ...

  4. linux虚拟机xshell安装

    目录 一:虚拟机安装 二:配置windows网络 三:linux操作系统安装 四:xshell安装使用 一:虚拟机安装 1.双击虚拟机软件 ---> 下一步 直至安装完毕 2.安装Linux操作 ...

  5. iGear 用了这个小魔法,模型训练速度提升 300%

    一个高精度AI模型离不开大量的优质数据集,这些数据集往往由标注结果文件和海量的图片组成.在数据量比较大的情况下,模型训练周期也会相应加长.那么有什么加快训练速度的好方法呢? 壕气的老板第一时间想到的通 ...

  6. clickhouse-mysql数据同步

    clickhouse版本:22.1.2.2 1.Mysql引擎(不推荐) CREATE DATABASE [IF NOT EXISTS] db_name [ON CLUSTER cluster] EN ...

  7. Mac OS Fusion Linux虚拟机网络设置

    1.设定网络为nat 2.ifconfig查看mac机的ip 3.进入虚拟机设定网络,手动指定自己ip为mac机网段ip,xxx.xxx.xxx.2是固定的路由及DNS的ip 4.关闭再打开网络即可访 ...

  8. aws 试题

    /* Domain 1 Design Resilient Architectures 1. Which of the following statements regarding S3 storage ...

  9. CNN-卷积神经网络简单入门(2)

    在上篇中,对卷积神经网络的卷积层以及池化层模块进行了简单的介绍,接下来将对卷积神经网络的整个运作流程进行分析,以便对CNN有个总体上的认知和掌握. 如下图,卷积神经网络要完成对图片数字的识别任务.网络 ...

  10. PyTorch 介绍 | BUILD THE NEURAL NETWORK

    神经网络由对数据进行操作的layers/modules组成.torch.nn 命名空间提供了所有你需要的构建块,用于构建你自己的神经网络.PyTorch的每一个module都继承自nn.Module. ...