[题解]RQNOJ PID86 智捅马蜂窝
链接: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 智捅马蜂窝的更多相关文章
- rqnoj86 智捅马蜂窝
题目描述 背景 为了统计小球的方案数,平平已经累坏了.于是,他摘掉了他那800度的眼镜,躺在树下休息. 后来,平平发现树上有一个特别不一样的水果,又累又饿的平平打算去把它摘下来. 题目描述 现在,将大 ...
- [题解]RQNOJ PID87 过河
链接:http://www.rqnoj.cn/problem/87 思路:动态规划 定义f[i][j]表示到达第 i 块给定石头用了 j 块添加石头的最少步数. 转移方程:f[i][j]=min{f[ ...
- [题解]RQNOJ PID85 三个袋子
链接:http://www.rqnoj.cn/problem/85 思路:一个排列问题,递推式很简单,f(n+1)=3*f(n)-1 ,由此可以推出通项公式,f(n)=0.5*3^(n-1)+0.5 ...
- [BZOJ1177][Apio2009]Oil
[BZOJ1177][Apio2009]Oil 试题描述 采油区域 Siruseri政府决定将石油资源丰富的Navalur省的土地拍卖给私人承包商以建立油井.被拍卖的整块土地为一个矩形区域,被划分为M ...
- DP——由蒟蒻到神犇的进阶之路
开始更新咯 DP专题[题目来源BZOJ] 一.树形DP 1.bzoj2286消耗战 题解:因为是树形结构,一个点与根节点不联通,删一条边即可, 于是我们就可以简化这棵树,把有用的信息建立一颗虚树,然后 ...
- Educational Codeforces Round 10 A. Gabriel and Caterpillar 模拟
A. Gabriel and Caterpillar 题目连接: http://www.codeforces.com/contest/652/problem/A Description The 9-t ...
- 题解-NOI2003 智破连环阵
题面 NOI2003 智破连环阵 有 \(m\) 个靶子 \((ax_j,ay_j)\) 和 \(n\) 个箭塔 \((bx_i,by_i)\).每个箭塔可以射中距离在 \(k\) 以内的靶子.第 \ ...
- 题解【RQNOJ PID497 0/1字串问题】
\[ \texttt{Description} \] 编程找出符合下列条件的字符串:①字符串中仅包含 0 和 1 两个字符:②字符串的长度为 n :③字符串中不包含连续重复三次的子串. \[ \tex ...
- 第三届“传智杯”全国大学生IT技能大赛(初赛A组)题解
留念 C - 志愿者 排序..按照题目规则说的排就可以.wa了两发我太菜了qwq #include<bits/stdc++.h> using namespace std; const in ...
随机推荐
- 5.14-HTTP间通信
1.社长社员通信WEBSOCKET WebSocket 是一种标准协议,用于在客户端和服务端之间进行双向数据传输.但它跟 HTTP 没什么关系,它是一种基于 TCP 的一种独立实现. 以前客户端想知道 ...
- Android学习笔记3
(5)练习做一个实现两个数相乘的APP ①.java代码: //MainActivity.java package com.example.hello; import android.content. ...
- 【刷题-LeetCode】240. Search a 2D Matrix II
Search a 2D Matrix II Write an efficient algorithm that searches for a value in an m x n matrix. Thi ...
- NAO机器人开发环境配置
python python2.7用于NAO开发 https://www.python.org/downloads/release/python-2718/ python3.6用于其他程序测试. htt ...
- 淘系工程师讲解的使用Spring特性优雅书写业务代码
使用Spring特性优雅书写业务代码 大家在日常业务开发工作中相信多多少少遇到过下面这样的几个场景: 当某一个特定事件或动作发生以后,需要执行很多联动动作,如果串行去执行的话太耗时,如果引入消息中 ...
- web服务组件
- 前端基础之SCC
目录 一:SCC 1.什么数SCC? 2.CSS3语法 3.语法结构 4.注释语法 5.css代码书写位置(引入方式) 二:scc代码书写位置(引入方式实战) 1.style内部直接编写css代码 2 ...
- python23day
内容回顾 面向对象 类:是具有相同属性和相似功能的一类事物 对象/实例:具体的,一类可以有多个对象 实例化 练习 # 定义一个圆形类,半径是这个圆的属性,实例化一个半径为5的圆形,一个半径为10的圆形 ...
- https的页面内嵌入http页面报错的问题
1.https的页面内嵌入http页面报错 在HTTPS的页面上嵌入http的页面时,浏览器会直接报错.比如在HTTPS页面上用 iframe 直接嵌入一个 http 页面,比如我们可以在百度上直接嵌 ...
- CF Round #687 Div2 简要题解
题面 A 可以发现,最远的几个人一定是 \((1, 1), (1, m), (n, 1), (n, m)\) 中的一个,直接计算即可. B 注意到颜色数量很少,直接暴力枚举最终的颜色后模拟即可. C ...