The Ninth Hunan Collegiate Programming Contest (2013) Problem F

本文介绍了一个基于FunnyCar Racing场景的最短路径问题,赛车需通过周期性开关的道路从起点到达终点。文章提供了使用堆优化的快速最短路径算法实现,并详细解释了如何处理有向边和道路的开放关闭周期。

Problem F

Funny Car Racing

There is a funny car racing in a city with n junctions and m directed roads.

The funny part is: each road is open and closed periodically. Each road is associate with two integers (a, b), that means the road will be open for a seconds, then closed for b seconds, then open for a seconds...  All these start from the beginning of the race. You must enter a road when it's open, and leave it before it's closed again.

Your goal is to drive from junction s and arrive at junction t as early as possible. Note that you can wait at a junction even if all its adjacent roads are closed.

Input

There will be at most 30 test cases. The first line of each case contains four integers n, m, s, t (1<=n<=300, 1<=m<=50,000, 1<=s,t<=n). Each of the next m lines contains five integers u, v, a, b, t (1<=u,v<=n, 1<=a,b,t<=105), that means there is a road starting from junction u ending with junction v. It's open for a seconds, then closed for b seconds (and so on). The time needed to pass this road, by your car, is t. No road connects the same junction, but a pair of junctions could be connected by more than one road.

Output

For each test case, print the shortest time, in seconds. It's always possible to arrive at t from s.

Sample Input

3 2 1 3
1 2 5 6 3
2 3 7 7 6
3 2 1 3
1 2 5 6 3
2 3 9 5 6

Output for the Sample Input

Case 1: 20
Case 2: 9

The Ninth Hunan Collegiate Programming Contest (2013) Problemsetter: Rujia Liu Special Thanks: Md. Mahbubul Hasan

   很明显的快速最短路,满足最优性,用堆优化,扩展边的时候判断2种情况。注意边是有向边。万变不离其宗。

 

#include <iostream>
#include <stdio.h>
#include <queue>
#include <stdio.h>
#include <string.h>
#include <vector>
#include <queue>
#include <set>
#include <algorithm>
#include <map>
#include <stack>
#include <math.h>
#define Max(a,b) ((a)>(b)?(a):(b))
#define Min(a,b) ((a)<(b)?(a):(b))
using namespace std ;
typedef long long LL ;
const int Max_N=308 ;
const LL inf=(LL)1000000000000000000 ;
struct Road{
    int V ;
    LL open_time ;
    LL close_time ;
    LL T ;
    Road(){} ;
    Road(int v ,LL o ,LL c ,LL t):V(v),open_time(o),close_time(c),T(t){} ;
};
vector<Road>vec[Max_N] ;
int N ,M ,S ,T ;
struct Node{
    int u ;
    LL Time ;
    Node(){} ;
    Node(int U ,LL t):u(U),Time(t){} ;
    friend bool operator < (const Node A ,const Node B){
         return A.Time>B.Time ;
    }
};
LL dist[Max_N] ;
void spfa(){
    fill(dist,dist+1+N,inf) ;
    priority_queue<Node>que ;
    que.push(Node(S,0)) ;
    dist[S]=0 ;
    while(!que.empty()){
        Node now = que.top()  ;
        que.pop() ;
        if(now.u==T){
            return ;
        }
        int u = now.u ;
        for(int i=0 ; i<vec[u].size() ;i++){
            Road r=vec[u][i] ;
            int v = r.V ;
            LL o_t = r.open_time ;
            LL c_t = r.close_time ;
            LL t = r.T ;
            if(r.T > o_t)
                continue ;
            LL res = ( now.Time%(o_t+c_t)+(o_t+c_t) ) % (o_t+c_t) ;
            if(res+t<=o_t&&now.Time+t<dist[v]){
                dist[v]=now.Time+t ;
                que.push(Node(v,dist[v]));
            }
            else if(now.Time+o_t+c_t-res+t<dist[v]){
                dist[v] = now.Time+o_t+c_t-res+t ;
                que.push(Node(v ,dist[v])) ;
            }
        }
    }
}
int main(){
   int k=1 ;
   int u ,v ,open_t ,close_t ,t;
   while(scanf("%d%d%d%d",&N,&M,&S,&T)!=EOF){
        for(int i=1;i<=N;i++)
            vec[i].clear()  ;
        for(int i=1;i<=M;i++){
            scanf("%d%d%d%d%d",&u,&v,&open_t,&close_t,&t) ;
            vec[u].push_back(Road(v,(LL)open_t,(LL)close_t,(LL)t)) ;
           // vec[v].push_back(Road(u,(LL)open_t,(LL)close_t,(LL)t)) ;
        }
        spfa() ;
        printf("Case %d: ",k++) ;
        cout<<dist[T]<<endl ;
   }
   return 0 ;
}

 

 

转载于:https://www.cnblogs.com/liyangtianmen/p/3372108.html

【顶级EI完整复现】【DRCC】考虑N-1准则的分布鲁棒机会约束低碳经济调度(Matlab代码实现)内容概要:本文介绍了名为《【顶级EI完整复现】【DRCC】考虑N-1准则的分布鲁棒机会约束低碳经济调度(Matlab代码实现)》的技术资源,聚焦于电力系统中低碳经济调度问题,结合N-1安全准则与分布鲁棒机会约束(DRCC)方法,提升调度模型在不确定性环境下的鲁棒性和可行性。该资源提供了完整的Matlab代码实现,涵盖建模、优化求解及仿真分析全过程,适用于复杂电力系统调度场景的科研复现与算法验证。文中还列举了大量相关领域的研究主题与代码资源,涉及智能优化算法、机器学习、电力系统管理、路径规划等多个方向,展示了广泛的科研应用支持能力。; 适合人群:具备一定电力系统、优化理论和Matlab编程基础的研究生、科研人员及从事能源调度、智能电网相关工作的工程师。; 使用场景及目标:①复现高水平期刊(如EI/SCI)关于低碳经济调度的研究成果;②深入理解N-1安全约束与分布鲁棒优化在电力调度中的建模方法;③开展含新能源接入的电力系统不确定性优化研究;④为科研项目、论文撰写或工程应用提供可运行的算法原型和技术支撑。; 阅读建议:建议读者结合文档提供的网盘资源,下载完整代码与案例数据,按照目录顺序逐步学习,并重点理解DRCC建模思想与Matlab/YALMIP/CPLEX等工具的集成使用方式,同时可参考文中列出的同类研究方向拓展研究思路。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值