[题解]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 ...
随机推荐
- SQL语句的分类:DQL、DML、DDL、DCL、TCL的含义和用途
MySQL中提供了很多关键字,将这些关键字 和 数据组合起来,就是常说的SQL语句,数据库上大部分的操作都是通过SQL语句来完成.日常工作中经常听到 DML.DDL语句这些名词,使用字母缩写来表达含义 ...
- [C语言基础] 数组与指针之间的引用
通过指针引用数组,通过数组引用指针,你搞明白了么?通过下面3种情形来了解一下数组和指针 Case 1. unsigned char arry[10]; unsigned char *ptr; unsi ...
- 动态多条件mysql模糊查询
sql拼接函数 public static String Instructor_sql_whole_study(String[] val_ids,String[] val_values) { Stri ...
- 白嫖党的福音!!!全新的Java300集视频(2022版)来了!
它来了它来了,经过一年时间的沉淀, [尚学堂]高淇Java300集完整版正式发布啦! 应广大网友和尚学堂忠实的孜孜学子以及听众朋友的要求,尚学堂在去年十月份就把预计在2022年发布的Java300集提 ...
- 【笔记】论文阅读:《Gorilla: 一个快速, 可扩展的, 内存式时序数据库》
英文:Gorilla: A fast, scalable, in-memory time series database 中文:Gorilla: 一个快速, 可扩展的, 内存式时序数据库
- 使用redis+lua实现SQL中的select intersect的效果
公众号文章地址 1.需求 业务中需要实现在两个集合中搜索数据,并返回交集. 用SQL的伪代码可以描述如下: select key from set1 where sorted_key between ...
- manjaro20WPS缺少字体
宋体等 sudo pacman -S ttf-wps-fonts Ariel和Times New Roman https://askubuntu.com/questions/651441/how-to ...
- Java中的wait方法 简单介绍。
一 wait方法怎么用? package com.aaa.threaddemo; /* * 多线程中的wait方法? public final void wait() throws Interrupt ...
- cloudcompare备忘录(1)
1.找点 然后直接在需要的位置上点就会出现这个点的信息了~! 2.想看一个三d的切面时候 先选中切的目标 点击小剪刀~ 点击鼠标左键四次来框选,然后点击鼠标右键确认 再点击这个按钮就切好了
- webpack4 mini-css-extract-plugin
在使用webpack的extract-text-webpack-plugin插件提取单独打包css文件时,报错,说是这个插件要依赖webpack3的版本. webpack4得使用mini-css-ex ...