题意:求期望红绿灯时间下,途径若干加油站,经过最多若干个红绿灯,起点与终点的最短路。
思路:每个有红绿灯的节点通过时间怎么算呢?事实上t=red*red/2/(red+green),然后把这个时间附加到节点的出边上。
随后我们建立分层图,第i层表示经过了i个红绿灯时,从源点到该点的最短路径长度。
如果没有油量限制,那么我们直接跑最短路就行了。
注意到加油站很少,于是我们枚举以每个加油站为起点,向其他加油站经过若干个红绿灯的最短路径。若此长度不大于最大油量,那么可以直接转移。
我们用上述信息构造新图,依旧是分层图,可是每一层仅有50个点,且没有油量限制。
一次最短路出解。
Code:
#include <map>
#include <queue>
#include <string>
#include <cstdio>
#include <cctype>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
typedef double f2;
#define _abs(x) ((x)>0?(x):-(x))
#define N 10010
int n, m, dep, lim, cost;
bool isGas[N];
f2 length[N];
map<string, int> M;
int id, S, T;
int Point_id, lab[11][N];
struct Node {
int lab;
f2 dis;