Gym - 102141D 通项公式 最短路
题目很长,但是意思就是给你n,A,B,C,D
n表示有n个城市 A是飞机的重量 B是一个常数表示转机代价 C是单位燃油的价格 D是一个常数
假设一个点到另外一个点的距离为整数L 起飞前的油量为f 则在这途中每飞行一单位距离 就花费(f+A)/D的燃油
#include <bits/stdc++.h>
typedef long long ll;
typedef long double lb;
using namespace std;
const int MAXN=,MAXM=;
int to[MAXM << ], nxt[MAXM << ], Head[MAXN], ed = ;
lb cost[MAXM << ];
int n;
inline void addedge(int u, int v, lb c) {
to[++ed] = v;
nxt[ed] = Head[u];
Head[u] = ed;
cost[ed] = c;
}
struct HeapNode {
int u;
lb d;
bool operator < (const HeapNode& rhs) const {
return d > rhs.d;
}
} zz;
lb mindist[MAXN];
bool vis[MAXN];
priority_queue<HeapNode> que;
void Hijkstra(int s) {
for (int i = ; i <= n; i++) {
mindist[i] = 4000000000000000000.0;
}
mindist[s] = 0.0;
memset(vis, , sizeof(vis));
zz.d = , zz.u = s;
que.push(zz);
while (!que.empty()) {
HeapNode x = que.top();
que.pop();
int u = x.u;
if (vis[u] || mindist[u] != x.d) {
continue;
}
vis[u] = true;
for (int v, i = Head[u]; i; i = nxt[i]) {
v = to[i];
if (mindist[v] > mindist[u] + cost[i]) {
mindist[v] = mindist[u] + cost[i];
//p[v]=u;
zz.d = mindist[v], zz.u = v;
que.push(zz);
}
}
}
}
void init(int x) {
ed = ;
for (int i = ; i <= x; i++) {
Head[i] = ;
}
}
struct node {
ll x, y;
} P[MAXN];
int main() {
int TC;
scanf("%d", &TC);
while (TC--) {
ll A, B, C, D;
scanf("%d %lld %lld %lld %lld", &n, &A, &B, &C, &D);
init(n);
for (int i = ; i <= n; i++) {
scanf("%lld %lld", &P[i].x, &P[i].y);
}
for (int i = ; i <= n; i++) {
for (int j = i + ; j <= n; j++) {
ll ax = abs(P[i].x - P[j].x);
ll ay = abs(P[i].y - P[j].y);
ll dis = ax * ax + ay * ay;
dis = ceil(sqrt(dis));
lb c = (pow((lb)D / (D - 1.0), dis) - 1.0) * A * C + B;
addedge(i,j,c),addedge(j,i,c);
}
}
Hijkstra();
printf("%.10Lf\n", mindist[n]);
}
return ;
}
Gym - 102141D 通项公式 最短路的更多相关文章
- Gym 101873C - Joyride - [最短路变形][优先队列优化Dijkstra]
题目链接:http://codeforces.com/gym/101873/problem/C 题意: 这是七月的又一个阳光灿烂的日子,你决定和你的小女儿一起度过快乐的一天.因为她真的很喜欢隔壁镇上的 ...
- Gym - 100625J Jailbreak 最短路+搜索
http://codeforces.com/gym/100625/attachments/download/3213/2013-benelux-algorithm-programming-contes ...
- GYM 101933D(最短路、二分、dp)
要点 非要先来后到暗示多源最短路,求最小的最大值暗示二分 二分内部的check是关键,dp处理一下,\(dp[i]\)表示第\(i\)笔订单最早何时送达,如果在ddl之前到不了则\(return\ 0 ...
- POJ 3635 - Full Tank? - [最短路变形][手写二叉堆优化Dijkstra][配对堆优化Dijkstra]
题目链接:http://poj.org/problem?id=3635 题意题解等均参考:POJ 3635 - Full Tank? - [最短路变形][优先队列优化Dijkstra]. 一些口胡: ...
- 【最短路】NEERC15 F Froggy Ford(2015-2016 ACM-ICPC)(Codeforces GYM 100851)
题目链接: http://codeforces.com/gym/100851 题目大意: 一只青蛙跳过宽为W的河,河中游N个石头,坐标xi,yi,现在往河中间添加一个石头,使得每次跳跃的最大的距离最小 ...
- 【最短路】BAPC2014 B Button Bashing (Codeforces GYM 100526)
题目链接: http://codeforces.com/gym/100526 http://acm.hunnu.edu.cn/online/?action=problem&type=show& ...
- Codeforces Gym 100338C Important Roads 最短路+Tarjan找桥
原题链接:http://codeforces.com/gym/100338/attachments/download/2136/20062007-winter-petrozavodsk-camp-an ...
- Gym - 100625D Destination Unknown 最短路
http://codeforces.com/gym/100625/attachments/download/3213/2013-benelux-algorithm-programming-contes ...
- Codeforces Gym 101630J Travelling from Petersburg to Moscow (最短路)
题目链接 http://codeforces.com/gym/101630/attachments 题解 zyb学长的题. 先枚举第\(k\)大的边权,设其边权为\(x\),然后把每条边边权减掉\(x ...
随机推荐
- 360安全卫士11.0史上最小版发布,去流氓,最精简,300MB内存轻松运行。完全不拖慢电脑的速度,由王宁诚意发布。
360安全卫士11.0史上最小版发布,也是史上最快版本.大家可能都不喜欢360,为什么?因为360太流氓,而大家想过如果360去掉了流氓会怎么样?对,那样360就会变成一个性能可以超过知名杀毒软件-s ...
- Aspose.Words提取word文档中的图片文件
/// <summary> /// 提取word中的图片 /// </summary> /// <param name="filePath">w ...
- spring效验
相关依赖 如果开发普通 Java 程序的的话,你需要可能需要像下面这样依赖: <dependency> <groupId>org.hibernate.validator< ...
- 小程序php支付,前后端分离
小程序端: xml: <button type="default" bindtap="payOrder">支付</button> js: ...
- centos7 64位如何配置网络
在虚拟机的操作的时候,修改 ifcfg-eno16777736 可能没有权限 su - //进入root用户状态chmod a+w ifcfg-eno16777736//把该文件修改为可写状态 我 ...
- 2017"百度之星"程序设计大赛 - 资格赛 1002 度度熊的王国战略
全局最小割 Stoer-Wagner (SW算法)优化 优化吃藕了,感谢放宽时限,感谢平板电视 (pb_ds) #include <iostream> #include <cstdi ...
- 剑指offer49:把字符串转换成整数
1 题目描述 将一个字符串转换成一个整数(实现Integer.valueOf(string)的功能,但是string不符合数字要求时返回0),要求不能使用字符串转换整数的库函数. 数值为0或者字符串不 ...
- 使用JavaScript随机生成数字混合字母的验证码
<script> // 封装一个随机生成数字的函数 function random(a, b) { var n = Math.round(Math.random() * (a - b) ...
- MySQL优化 - 性能分析与查询优化(转)
出处: MySQL优化 - 性能分析与查询优化 优化应贯穿整个产品开发周期中,比如编写复杂SQL时查看执行计划,安装MySQL服务器时尽量合理配置(见过太多完全使用默认配置安装的情况),根据应用负载 ...
- Spring Boot 获取Bean对象实体
一.实现 ApplicationContextAware 接口 package com.zxguan; import org.springframework.beans.BeansException; ...