先上题目:

12661 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
Sample Output
Case 1: 20
Case 2: 9

  题意:给出一个有向图,每条边都有三个值,打开时间间隔,关闭时间间隔,通过它需要多少时间,路的开关是循环往复的。给你起点和终点,问你最少需要多少时间才可以从起点到达终点(保证一定存在这种路)。

  这其实是求最短路,用DIJ求最短路,然后对于从某个点开始可以到达的下一个点,在分析是否需要更新的时候,需要判断当前时刻路开了没有,如果开了看看够不够时间过去,然后根据这些情况更新最小值就可以了。这里需要注意的东西就是这事有向图不是无向图。

上代码:

 #include <cstdio>
#include <cstring>
#include <algorithm>
#define MAX 50002
#define ll long long
#define INF (((ll)1)<<60)
using namespace std; typedef struct edge{
int to,next;
ll a,b,c,s;
}edge; edge e[MAX<<];
int p[],tot;
int n,m,st,ed;
ll dis[MAX]; void dij(){
bool f[]={};
for(int i=;i<=n;i++){
dis[i]=INF;
}
dis[st]=;
for(int i=;i<n;i++){
int u;
ll dd=INF;
for(int j=;j<=n;j++){
if(!f[j] && dd>dis[j]) {
dd=dis[j];
u=j;
}
}
if(dd==INF) break;
f[u]=;
for(int j=p[u];j!=-;j=e[j].next){
ll t=dis[u];
ll r=t%e[j].s;
if(r>=e[j].a){
t+=(e[j].s-r)+e[j].c;
}else{
if(e[j].a-r>=e[j].c) t+=e[j].c;
else t+=e[j].s-r+e[j].c;
}
dis[e[j].to]=min(t,dis[e[j].to]);
}
}
} inline void add(int u,int v,int a,int b,int c){
e[tot].to=v; e[tot].next=p[u];
e[tot].a=a; e[tot].b=b; e[tot].c=c; e[tot].s=a+b;
p[u]=tot++;
} int main()
{
int t,u,v,a,b,c;
//freopen("data.txt","r",stdin);
t=;
while(scanf("%d %d %d %d",&n,&m,&st,&ed)!=EOF){
memset(p,-,sizeof(p));
tot=;
for(int i=;i<m;i++){
scanf("%d %d %d %d %d",&u,&v,&a,&b,&c);
if(c<=a){
add(u,v,a,b,c);
//add(v,u,a,b,c);
}
}
dij();
printf("Case %d: %lld\n",t++,dis[ed]); }
return ;
}

/*12661*/

UVa - 12661 - Funny Car Racing的更多相关文章

  1. UVa 12661 Funny Car Racing - spfa

    很简单的一道最短路问题.分情况处理赛道的打开和关闭. Code /** * UVa * Problem#12661 * Accepted * Time:50ms */ #include<iost ...

  2. UVa 12661 - Funny Car Racing(Dijkstra)

    链接: https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem& ...

  3. UVA 12661 Funny Car Racing 有趣的赛车比赛(最短路,变形)

    题意:赛道有n个交叉点,和m条单向路径(有重边),每条路都是周期性关闭的,且通过仍需一段时间.在比赛开始时,所有道路刚好打开,选择进入该道路必须满足“在打开的时间段进入,在关闭之前出来”,即不可在路上 ...

  4. UVa 12661 Funny Car Racing (dijkstra)

    题意:给定一个有向图,每条路有5个整数修饰,u, v, a, b, t,表示起点为u,终点为v,打开时间a,关闭时间为b,通过时间为t,打开关闭是交替进行的, 问你从s到t最短时间是多少. 析:使用d ...

  5. UVA - 12661 Funny Car Racing (Dijkstra算法)

    题目: 思路: 把时间当做距离利用Dijkstra算法来做这个题. 前提:该结点e.c<=e.a,k = d[v]%(e.a+e.b); 当车在这个点的1处时,如果在第一个a这段时间内能够通过且 ...

  6. UVa 12661 Funny Car Racing【 dijkstra 】

    题意:给出n个点,m条路,每条路用5个整数表示u,v,a,b,t u表示这条路的起点,v表示终点,a表示打开时间,b表示关闭时间,t表示通过这条道路需要的时间 看的紫书,因为边权不再仅仅是路上的时间, ...

  7. UVa 12661 (单源最短路) Funny Car Racing

    题意: 有一个赛车跑道,可以看做一个加权有向图.每个跑道(有向边)还有一个特点就是,会周期性地打开a秒,然后关闭b秒.只有在赛车进入一直到出来,该跑道一直处于打开状态,赛车才能通过. 开始时所有跑道处 ...

  8. UVA 12661(动态权值+最短路,dij)

    题意:赛车背景,给你n个节点,m条边的图以及起点和终点:其中每条边的信息包括u(起点),v(终点),a(开启的时间),b(关闭的时间),d(通过这条道路的时间):求最短通过的时间,其中车在进的时候,保 ...

  9. 紫书 例题11-11 UVa 12661 (dihkstra变形)

    这道题主要比较权值的时候要改变一下,其他地方基本一样. 比较权值的时候要考虑边的时间与a, b 可以设相对于当前边的时间now, 则now = d[u] % (a+b), 也就是当前这个边进行到整个a ...

随机推荐

  1. MVC web api 返回JSON的几种方式,Newtonsoft.Json序列化日期时间去T的几种方式。

    原文链接:https://www.muhanxue.com/essays/2015/01/8623699.html MVC web api 返回JSON的几种方式 1.在WebApiConfig的Re ...

  2. 【原创】Vue项目中各种功能的实现

    已完成: 后台的管理功能: 这里用的组件是 element-UI  ====> NavMenu ◆首先是排版 : <div class="manage-page fillcont ...

  3. MySQL数据库笔记总结

    MySQL数据库总结 一.数据库简介 1. 数据 所谓数据(Data)是指对客观事物进行描述并可以鉴别的符号,这些符号是可识别的.抽象的.它不仅仅指狭义上的数字,而是有多种表现形式:字母.文字.文本. ...

  4. Ansible+Jenkins+Gitlab搭建及配置

    Ansible+Jenkins+Gitlab搭建及配置,已经生产环境使用,运行良好. 主机组文件里面好多ip敏感信息就不写了

  5. 服务器上oracle的监听设置

    1.查看本机的计算机名 2.修改etc/host 3.修改oracle的listener.ora(我服务器上的路径:) 4.修改tnsnames.ora(和上边文件一个目录)

  6. C# asp.net repeater实现排序功能,自动排序,点击头部排序,点击列排序

    在网上看到好多关于repeater排序的,自己动手用了,发现一些问题,贴源码后把发现的问题以及解决方法给出 repeater实现排序功能(单击升序排列,再单击降序排列).原理很简单,在<TD&g ...

  7. 用CSS样式写选择框右侧小三角

    直接上代码! <!DOCTYPE html><html lang="en"><head> <title>小三角</title& ...

  8. android黑科技系列——获取加固后应用App的所有方法信息

    一.前言 在逆向应用的时候,我们有时候希望能够快速定位到应用的关键方法,在之前我已经详细介绍了一个自己研发的代码动态注入工具icodetools,来进行动态注入日志信息到应用中,不了解的同学可以查看这 ...

  9. ES6学习之箭头函数

    ES6学习笔记--箭头函数 箭头函数一直在用,最近突然想到重新看一下箭头函数的用法,所以这里做一些总结. 箭头函数长这个样子: let fn = a => a++; // fn 是函数名, a= ...

  10. 初始MongoDB------MongoDB的安装

    MongoDB在Windows的安装是很简单的,无论是安装包还是绿色包,安装出来的都是这些文件   重点是Bin中的东西   特别是前两个的执行文件 mongod进程就是启动MongoDB数据库的进程 ...